def leaders(xs, top=10):
    counts = defaultdict(int)
for x in xs:
    counts[x] += 1
return sorted(list(counts.items()), reverse=True, key=lambda tup: tup[1])[:top]
Python: how to get sorted count of items in a list?