#C13229. Count the Frequency of Characters
Count the Frequency of Characters
Count the Frequency of Characters
Given a string s
, count the frequency of each character (case-sensitive) in the string. The task is to output a dictionary-like representation where the keys are the characters and the values are their counts. The order of keys should follow their first occurrence in the string.
For example, if s = "Programming"
, then the output should be:
Note that the function should treat uppercase and lowercase letters as distinct characters.
inputFormat
The input consists of a single line containing the string s
.
If the input is empty, you should output an empty dictionary: {}
.
outputFormat
Output a dictionary in the following format: {'char1': count1, 'char2': count2, ...}
representing the frequency of each character in the string. The keys should be enclosed in single quotes, and each pair should be separated by a comma and a space.
Programming
{'P': 1, 'r': 2, 'o': 1, 'g': 2, 'a': 1, 'm': 2, 'i': 1, 'n': 1}