Back to problems

Top 10 Words

Algorithm · Robinhood · Medium

Write a function top_words(s) that processes a string s and returns the ten most frequent words, treating uppercase and lowercase letters as equivalent. Along with each distinct word, provide its occurrence count. A word is formed by a maximal contiguous run of English letters (A–Z or a–z). Every character outside that range is handled as a word separator and discarded. All letters are converted to lowercase when counting. For every word in the top 10, produce a pair [word,…

Checking your access…