Count Word Frequency and Print Top Three Words
PayPalData Scientist · OnsiteLast updated
This question evaluates proficiency in basic Python programming, string/text processing, frequency counting and sorting algorithms, reflecting core competencies for data manipulation tasks.
Scenario
First-round Python coding screening
Question
Using only basic Python, write a function that receives a list of strings and returns a dictionary mapping each unique word to its frequency. Then print the three most frequent words in descending order.
Hints
Build dict with a for-loop; sort by value to get top-3.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.