collections.Counter()
collections.Counter() is a Python function in the Collections Module category. A dict subclass for counting hashable objects. Elements are stored as keys and counts as values. The syntax is collections.Counter([iterable]). Parameters: iterable or mapping. Returns: Counter object. A typical example: from collections import Counter
c = Counter("abracadabra")
c["a"] # 5
c.most_common(2) # [("a",5), ("b",2)]. A close sibling is collections.deque(), which returns a double-ended queue (deque) with efficient O(1) appends/pops from both ends. A close sibling is deque.append(), which adds x to the right side of the deque. A close sibling is deque.appendleft(), which adds x to the left side of the deque. A close sibling is deque.pop(), which removes and returns the rightmost element. Raises IndexError if empty. More about this category: Specialized container datatypes — deque, Counter, defaultdict, namedtuple, OrderedDict. For a broader walkthrough, read the Collections Module guide. Related Collections Module entries: collections.deque(), deque.append(), deque.appendleft(), deque.pop(), deque.popleft(), deque.extend().