Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Count how many times each word appears in the cat and the dog and the bird.
split() cuts a sentence into words. Then count in the same way.
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.
Plan. split() gives the list of words. Then count each one in a dictionary.
The result is {'the': 3, 'cat': 1, 'and': 2, 'dog': 1, 'bird': 1}.
Check. , the number of words in the sentence. ✓
Log in to join the discussion.
Loading…