Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Count the words of "the cat and the hat and the bat" with a dictionary. Which word is the most common, and how many times does it appear?
counts[word] = counts.get(word, 0) + 1
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
The counts are {"the": 3, "cat": 1, "and": 2, "hat": 1, "bat": 1}.
The most common word is the, with times. The next is and with .
Check. , and the sentence has words. ✓
Log in to join the discussion.
Loading…