#C13164. Character Frequency Counter
Character Frequency Counter
Character Frequency Counter
You are given a string that may contain alphabetic characters, digits, spaces, and punctuation marks. Your task is to count the frequency of each alphabetic character in the string ignoring case and disregarding all non-alphabetic characters. The order of the characters in the output should follow their first appearance in the input.
For example, for the input string aabbcc
, the output should be {'a': 2, 'b': 2, 'c': 2}
and for Hello, World!
the output should be {'h': 1, 'e': 1, 'l': 3, 'o': 2, 'w': 1, 'r': 1, 'd': 1}
.
The frequency is defined by the number of occurrences of each character, and only alphabetic characters (A-Z or a-z) are counted after converting them to lowercase.
Mathematically, if you denote the input string by \( S \) and a lowercase alphabetic character by \( c \), then the frequency \( f(c) \) is defined as:
\( f(c) = \#\{ i \mid S_i \text{ is an alphabet} \land \text{toLower}(S_i) = c \} \)
inputFormat
The input consists of a single line containing the string \( S \), which may include spaces and punctuation.
outputFormat
Output the dictionary representation of the frequency of each alphabetic character in \( S \). The dictionary should be printed in the format similar to Python's dictionary literal (e.g. {'a': 2, 'b': 3}
) in the order of the characters' first occurrence.
aabbcc
{'a': 2, 'b': 2, 'c': 2}