#K58272. Character Frequency Analysis
Character Frequency Analysis
Character Frequency Analysis
You are given a string S as input. Your task is to analyze the frequency of each character in the string, excluding spaces, and output the result as a list of tuples. Each tuple contains a character and its frequency, and the order of the tuples must reflect the order in which the character first appears in S.
Note: The list should be formatted in the form:
[ [('c_1', f_1), ('c_2', f_2), \ldots, ('c_k', f_k)] ]
where each \(c_i\) is a character (other than space) in the string and \(f_i\) is its frequency.
Input: The input is provided via standard input as a single line containing the string S.
Output: Print the frequency analysis result on standard output in the exact list format shown above.
inputFormat
The input consists of a single line containing a string S. The string may include spaces; however, spaces are to be ignored during the frequency analysis.
outputFormat
Output a list of tuples representing the frequency of each character (excluding spaces) in the order of their first appearance. The format should exactly match the following example:
[('h', 1), ('e', 1), ('l', 3), ('o', 2), ('w', 1), ('r', 1), ('d', 1)]## sample
hello world
[('h', 1), ('e', 1), ('l', 3), ('o', 2), ('w', 1), ('r', 1), ('d', 1)]