Intermediate
Top k frequent words
Write top_words(text, k) that lowercases text, splits it on whitespace, and returns a list of the k most frequent words. Higher counts come first. Words with equal counts are ordered alphabetically.
If there are fewer than k distinct words, return all of them. Empty text gives [].
What Check tests
- Highest counts first
- Ties are alphabetical
- Case is ignored
- k larger than the number of words
- Empty text
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.