Create a new, empty Counter object. And if given, count elements from an input iterable. Or, initialize the count from another mapping of elements to their counts. >>> c = Counter() # a new, empty counter >>> c = Counter('gallahad')
(self, iterable=None, /, **kwds)
| 600 | # Knuth, TAOCP Vol. II section 4.6.3 |
| 601 | |
| 602 | def __init__(self, iterable=None, /, **kwds): |
| 603 | '''Create a new, empty Counter object. And if given, count elements |
| 604 | from an input iterable. Or, initialize the count from another mapping |
| 605 | of elements to their counts. |
| 606 | |
| 607 | >>> c = Counter() # a new, empty counter |
| 608 | >>> c = Counter('gallahad') # a new counter from an iterable |
| 609 | >>> c = Counter({'a': 4, 'b': 2}) # a new counter from a mapping |
| 610 | >>> c = Counter(a=4, b=2) # a new counter from keyword args |
| 611 | |
| 612 | ''' |
| 613 | super().__init__() |
| 614 | self.update(iterable, **kwds) |
| 615 | |
| 616 | def __missing__(self, key): |
| 617 | 'The count of elements not in the Counter is zero.' |