Python - Counter Dict - Simplify counting with collections
Counter(iterable) is a subclass of Python dict built-in.
The Counter class is a variation of dictionary that makes counting of elements in iterables way easier.
Counter is designed for counting hashable items in an iterable.
It provides an easy way to count elements in lists, strings, and other iterables,
allowing you to access counts by calling the keys.
Counter has method most_common(n=None).
It lists the n most common elements and their counts, (from high to low) in tuples.
If you don't provide n, it lists all elements counts.
And Counter also has method elements().
It creates an iterator with elements repeating as many times as their count.
It also acts similar to defaultdict in some cases, when you will call a key that don't exist, Counter
will return a 0.
To use Counter, you must import it from the collections module.