The Letter Tally
A easy Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- easy
- Seniority
- L3
Problem
Implement a CharCounter class whose constructor takes a string `text`, and provide a top-level driver function `char_counter_demo(text)` that constructs CharCounter(text) and returns the result of its `get_counts()` method. `get_counts()` returns a list of `[char, count]` pairs (each pair a two-element list), one per distinct character, sorted alphabetically by character (standard codepoint order, so uppercase letters sort before lowercase). Ignore spaces and punctuation: count only alphanumeric characters. Counting is case-sensitive, so 'A' and 'a' are distinct. For a string with no alphanumeric characters, return an empty list.
Summary
Each character in the string has a count to answer for.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.