I think, collections.Counter is the most magic and powerful container in Python. This is smart and beautiful multiset realization. Let’s have a look at what Counter can do. Basic usage Basic usage for Counter is to count some element (for example, words) in a sequence and get N most popular. from collections import Counter words = 'to be or not to be'.split() c = Counter(words) # Counter({'to': 2, 'be': 2, 'or': 1, 'not': 1}) c.