Exercise 2 solution import re from collections import Counter WORD = re.compile(r"[a-z]+(?:'[a-z]+)?") def top_words(text, n=3): return Counter(WORD.findall(text.lower())).most_common(n) text = "The cat and the hat. The CAT didn't sit; the hat didn't mind." print(top_words(text)) print(top_words(text, 5)) # [('the', 4), ('cat', 2), ('hat', 2)] # [('the', 4), ('cat', 2), ('hat', 2), ("didn't", 2), ('and', 1)] (All lines were run and printed exactly what is shown.) Explanation: lower-casing first makes The and the count as one word, and the optional apostrophe part keeps didn't whole instead of splitting it.