A note on Python Collections.Counter

Srikanth Potukuchi
2 min readFeb 28, 2023

One of the most useful features of Python is its built-in data structures. One such data structure is the collections.Counter module, which is used to count the occurrences of elements in a sequence.

The collections.Counter is a subclass of the dictionary object, which takes an iterable as an argument and returns a dictionary where the keys are the elements of the iterable, and the values are the count of occurrences of that element in the iterable.

Let’s take an example to understand how the collections.Counter module works:

--

--

Srikanth Potukuchi

I am working as a Lead Data Scientist in Canada. Passionate about data science since 2014. I started with SQL , R and SAS; later picked up Python.