CoreChallenge 11 of 34

Most common words

Write top_words(text, n) that returns the n most frequent words as a of (word, count) , most frequent first. Compare words case-insensitively and strip punctuation. ties alphabetically.

Examples
top_words("the cat and the hat and the bat", 2) → [("the", 3), ("and", 2)]
Exercise

Most common words

3 checks
import string


def top_words(text, n):
    ...


print(top_words("the cat and the hat and the bat", 2))
 
Python (loads on first run)Ctrl+Enter runs
Output
Press Run to try your code, then Check answer to grade it.