Basic frequency count
Input
most_common(['apple', 'banana', 'apple'], 2)
Output
[('apple', 2), ('banana', 1)]
apple appears twice and banana once; we return the top 2 items.
Full lesson preview
Use collections.Counter to find the top-N most frequent items in a list, with deterministic tie-breaking.
Problem statement
Task
Examples
Input
most_common(['apple', 'banana', 'apple'], 2)
Output
[('apple', 2), ('banana', 1)]
apple appears twice and banana once; we return the top 2 items.
Input format
Output format
Constraints
Samples
Input
most_common([1, 2, 2, 3], 10)
Output
[(2, 2), (1, 1), (3, 1)]
n is larger than distinct items, so return all items sorted by count then item.