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
3 checksMost common words
import string
def top_words(text, n):
...
print(top_words("the cat and the hat and the bat", 2))
Press Run to try your code, then Check answer to grade it.