#C12995. Letter Frequency Counting
Letter Frequency Counting
Letter Frequency Counting
Given a string s, your task is to count the frequency of every character present in the string. The counting must preserve the order in which each character first appears in s.
For each character c in the string, compute the number of times c appears, i.e. $$ f(c)=\text{number of occurrences of } c $$.
The output should be a Python-style dictionary with single quotes around the characters and should exactly reflect the order of the first occurrence of each character.
Note: The input string may contain spaces and punctuation. For an empty string, output an empty dictionary: {}.
inputFormat
The input is provided to standard input (stdin) as a single string that may contain spaces and punctuation. You can assume the input occupies one line (excluding the newline character at the end).
For example:
hello
outputFormat
Output the frequency dictionary of the characters in the input string to standard output (stdout). The dictionary should follow the Python convention, with keys enclosed in single quotes, and items separated by commas. The order of the keys should be the order in which the characters first appear in the input.
For example, given the input hello
, the expected output is:
{'h': 1, 'e': 1, 'l': 2, 'o': 1}## sample
hello
{'h': 1, 'e': 1, 'l': 2, 'o': 1}