Dictionaries and counting · Python exercise
Count non-space characters in a line and print a sorted table.
Read one line of text. Count each character except the space character. Print one line per distinct character in ascending character order in the format char count. Comparison is case-sensitive.
Example 1
Input
hello
Output
e 1 h 1 l 2 o 1
Example 2
Input
aab b
Output
a 2 b 2
How testing works
Your code runs once per test case with that case's standard input. Output is compared after normalising trailing spaces and blank lines at the end. Use input() without a prompt when the exercise expects clean output.
Loading editor…
Press Run tests to execute your code against every input case. Python runs in a Web Worker in your browser.