📘
Tokenize and Count
EasyText Processing
Given a string of text, split it into lowercase words (splitting on whitespace), and return a dictionary mapping each word to its frequency count.
Words should be converted to lowercase before counting. The output dictionary should be printed with keys in sorted order.
Example:
- Input: "The cat sat on the mat"
- After lowercasing and splitting: ["the", "cat", "sat", "on", "the", "mat"]
- Frequencies: {"cat": 1, "mat": 1, "on": 1, "sat": 1, "the": 2}
Example:
Input:
The cat sat on the mat
Output:
{'cat': 1, 'mat': 1, 'on': 1, 'sat': 1, 'the': 2}Reasoning:
Step 1: Lowercase the text "The cat sat on the mat" becomes "the cat sat on the mat"
Step 2: Split into words ["the", "cat", "sat", "on", "the", "mat"]
Step 3: Count frequencies
- "the" appears 2 times
- "cat", "sat", "on", "mat" each appear 1 time
Step 4: Sort by key and output {'cat': 1, 'mat': 1, 'on': 1, 'sat': 1, 'the': 2}
Constraints:
- Input: A single line of text (string)
- Split on whitespace only
- Convert all words to lowercase before counting
- Output: A dictionary printed with keys in sorted order
- Words contain only alphabetic characters and whitespace
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.