← All Exercises
Python Collections Counter
intermediatepython
Background
Counter is a specialized dictionary for counting hashable objects, with methods for common statistical operations.
Problem
Write a function that takes a list of words and returns the 3 most common words with their counts using Counter.
Input
A list of strings (words).
Output
A list of (word, count) tuples for the 3 most common words.
Sample tests
Sample 1
Input: ["a","b","a","c","a","b"]
Expected: [("a",3),("b",2),("c",1)]Your solution
Learning objective
Learn collections.Counter for frequency counting and most_common extraction.