Home | History | Annotate | Download | only in Lib

Lines Matching refs:Counter

7 * Counter      dict subclass for counting hashable objects
13 __all__ = ['Counter', 'deque', 'defaultdict', 'namedtuple', 'OrderedDict']
404 ### Counter
407 class Counter(dict):
412 >>> c = Counter('abcdeabcdabcaba') # count elements from a string
433 >>> d = Counter('simsalabim') # make another counter
434 >>> c.update(d) # add in the second counter
438 counter
440 Counter()
443 in the counter until the entry is deleted or the counter is cleared:
445 >>> c = Counter('aaabbc')
459 '''Create a new, empty Counter object. And if given, count elements
463 >>> c = Counter() # a new, empty counter
464 >>> c = Counter('gallahad') # a new counter from an iterable
465 >>> c = Counter({'a': 4, 'b': 2}) # a new counter from a mapping
466 >>> c = Counter(a=4, b=2) # a new counter from keyword args
470 raise TypeError("descriptor '__init__' of 'Counter' object "
476 super(Counter, self).__init__()
480 'The count of elements not in the Counter is zero.'
488 >>> Counter('abcdeabcdabcaba').most_common(3)
500 >>> c = Counter('ABCABC')
505 >>> prime_factors = Counter({2: 2, 3: 3, 17: 1})
526 'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
531 Source can be an iterable, a dictionary, or another Counter instance.
533 >>> c = Counter('which')
535 >>> d = Counter('watch')
536 >>> c.update(d) # add elements from another counter
549 raise TypeError("descriptor 'update' of 'Counter' object "
563 super(Counter, self).update(iterable) # fast path when counter is empty
576 Source can be an iterable, a dictionary, or another Counter instance.
578 >>> c = Counter('which')
580 >>> c.subtract(Counter('watch')) # subtract elements from another counter
588 raise TypeError("descriptor 'subtract' of 'Counter' object "
616 super(Counter, self).__delitem__(elem)
630 # To strip negative and zero counts, add-in an empty counter:
631 # c += Counter()
636 >>> Counter('abbb') + Counter('bcc')
637 Counter({'b': 4, 'c': 2, 'a': 1})
640 if not isinstance(other, Counter):
642 result = Counter()
655 >>> Counter('abbbc') - Counter('bccd')
656 Counter({'b': 2, 'a': 1})
659 if not isinstance(other, Counter):
661 result = Counter()
674 >>> Counter('abbb') | Counter('bcc')
675 Counter({'b': 3, 'c': 2, 'a': 1})
678 if not isinstance(other, Counter):
680 result = Counter()
694 >>> Counter('abbb') & Counter('bcc')
695 Counter({'b': 1})
698 if not isinstance(other, Counter):
700 result = Counter()