Dictionaries and counting · Python exercise
Count each word in a line and print the counts alphabetically.
Read one line of text. Count each word using case-insensitive comparison, then print one line per distinct word in alphabetical order in the format word count.
Example 1
Input
the cat the dog the
Output
cat 1 dog 1 the 3
Example 2
Input
Hello hello
Output
hello 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.