What is it?
a subclass for counting hashable objects.
class Counter(dict):
    def __init__(self, iterable=None, /, **kwds):
        super().__init__()
        self.update(iterable, **kwds)
Counter([1,2,3,4])
"""
list is not hashable but self.update()
converts the list to hashable object.
"""
When to use?
- Arithmetic operations like addition, subtraction, intersection, and union
- to count
 
![Cover image for [Python] Collections.Counter](https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyfhna1b4wu2gk5f06800.png) 
              
 
    
Top comments (0)