top_k(items, k) returning the k most common elements as a list of (item, count) tuples using collections.Counter.most_common — the standard library beats hand-rolled tallying.top_k(['a', 'b', 'a', 'c', 'a', 'b'], 2)
[('a', 3), ('b', 2)]a appears 3 times, b twice.
from collections import Counter.
Counter(items).most_common(k) is the whole job.