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
Top comments (0)