Word Counter
Python
20 pts
Word Counter
Write a function count_words(text) that returns a dictionary. Each key is a word and each value is how many times the word appears.
- Ignore upper and lower case:
"Tea"and"tea"are the same word. Keys are lowercase. - Remove these punctuation marks from the text first:
. , ! ? - Words are separated by spaces.
count_words("Tea, tea and coffee!")
# {"tea": 2, "and": 1, "coffee": 1}
Checklist
- Define
count_words(text)that returns a dictionary. - Count every word.
- Ignore case and punctuation.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
