Skip to content
C

Word Frequency with Counter

Easypython

Given a line of words, use collections.Counter to find and print the 3 most common words.

What the problem means: Counter is a Standard Library tool built exactly for this — counting how many times each item appears — so you don't need to write the counting loop yourself.

Approach: split the line into words, build a Counter from them, and call .most_common(3).

Input: One line: space-separated words.

Output: One line: the 3 most common words with their counts, as a Python list of tuples.

Input (stdin)

Output

Run your code to see output here...