CodeMIRAI
0 XP

Most common word

Medium +50 XP Solved

Read a line of lower-case words separated by spaces. Print the word that appears most often, followed by a space and its count.

If several words tie, print the one that comes first alphabetically.

Input
the cat and the hat
Expected output
the 2
Input
a b c b a
Expected output
a 2
Show a hint

Count with a dictionary, then pick the word with the highest count; sort ties by the word itself.

Show a solution
Python
Loading the editor…
Run the tests to check your solution.