The Three-Class Character Tally
Context
A finite string is viewed as a sequence of symbols. Each symbol belongs to exactly one of three classes: alphabetic characters, decimal digits, or all remaining characters. Determine how many symbols belong to each class.
Problem
Write a function that examines every character in symbols exactly once and counts the characters in three disjoint classes. An alphabetic character is an uppercase or lowercase English letter. A numeric character is one of the decimal digits 0 through 9. Every other character, including whitespace and punctuation, belongs to the remaining class. Return an integer list containing the totals in this order: alphabetic, numeric, other. Repeated characters are counted separately, and an empty string produces three zero totals.
Examples
symbols = "Hello, World! 123"[10, 3, 4]symbols = "A1-bB2!!"[3, 2, 3]symbols = " 007 #"[0, 3, 5]Constraints
0 <= len(symbols) <= 100000symbols: alphanumericspaces and punctuation may also occur.- Types:
symbolsis str; result is int[]
Function signature
def count_character_classes(symbols: str) -> list[int]
symbolsstr- The string whose characters are classified and counted.
- returns list[int]
- Three integers in order: the number of alphabetic characters, numeric characters, and other characters.
Adapted from MBPP problem task_828 (CC BY 4.0). Rewritten, extended and verified by Iksha.