Word Frequency
beginnerUp next
Up next
Output will appear here...
The starter code reads a line of text. Count how many times each word appears, ignoring capitalization, and print one line per word in the format word: count. List the words in the order they first appear.
For the input the cat and the hat, a correct solution prints:
the: 2
cat: 1
and: 1
hat: 1
Tip
Lowercase the text, use .split() to get the words, then use counts.get(word, 0) + 1 to update the dictionary. Dictionaries keep the order that keys were added in.
No comments yet. Start the discussion.