EasyPython
Dictionary Comprehension — Word Frequency
PythonDictionariesStrings
Implement solve(text) that returns a dictionary mapping each unique word (lowercased) to the number of times it appears in the text.
- Split on whitespace only.
- Lowercase all words before counting.
- Punctuation attached to words should be stripped (only
.,!?;:at start/end of each word).
Examples
solve("Hello hello HELLO")→{"hello": 3}solve("the cat sat on the mat")→{"the": 2, "cat": 1, "sat": 1, "on": 1, "mat": 1}solve("")→{}
Sample tests
Test #1Classic sentence
Input: ["the cat sat on the mat"]
Output: {"on":1,"cat":1,"mat":1,"sat":1,"the":2}
Test #2Empty string
Input: [""]
Output: {}
Test #3Same word, different cases
Input: ["Hello hello HELLO"]
Output: {"hello":3}