Counter

A dictionary from the collections module that counts how many times each item occurs.

In more detail

Counter(words) tallies a list in one call, and most_common(3) returns the three most frequent items with their counts. Missing items count as 0 rather than raising KeyError.

Example

from collections import Counter
Counter("mississippi").most_common(2)

Related terms

Taught in

References