MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Lib/collections/__init__.py:602–614  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.'

Callers

nothing calls this directly

Calls 2

updateMethod · 0.95
superClass · 0.85

Tested by

no test coverage detected