Home | History | Annotate | Download | only in python2.7

Lines Matching refs:Counter

1 __all__ = ['Counter', 'deque', 'defaultdict', 'namedtuple', 'OrderedDict']
378 ### Counter
381 class Counter(dict):
386 >>> c = Counter('abcdeabcdabcaba') # count elements from a string
407 >>> d = Counter('simsalabim') # make another counter
408 >>> c.update(d) # add in the second counter
412 >>> c.clear() # empty the counter
414 Counter()
417 in the counter until the entry is deleted or the counter is cleared:
419 >>> c = Counter('aaabbc')
433 '''Create a new, empty Counter object. And if given, count elements
437 >>> c = Counter() # a new, empty counter
438 >>> c = Counter('gallahad') # a new counter from an iterable
439 >>> c = Counter({'a': 4, 'b': 2}) # a new counter from a mapping
440 >>> c = Counter(a=4, b=2) # a new counter from keyword args
443 super(Counter, self).__init__()
447 'The count of elements not in the Counter is zero.'
455 >>> Counter('abcdeabcdabcaba').most_common(3)
467 >>> c = Counter('ABCABC')
472 >>> prime_factors = Counter({2: 2, 3: 3, 17: 1})
493 'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
498 Source can be an iterable, a dictionary, or another Counter instance.
500 >>> c = Counter('which')
502 >>> d = Counter('watch')
503 >>> c.update(d) # add elements from another counter
522 super(Counter, self).update(iterable) # fast path when counter is empty
535 Source can be an iterable, a dictionary, or another Counter instance.
537 >>> c = Counter('which')
539 >>> c.subtract(Counter('watch')) # subtract elements from another counter
567 super(Counter, self).__delitem__(elem)
581 # To strip negative and zero counts, add-in an empty counter:
582 # c += Counter()
587 >>> Counter('abbb') + Counter('bcc')
588 Counter({'b': 4, 'c': 2, 'a': 1})
591 if not isinstance(other, Counter):
593 result = Counter()
606 >>> Counter('abbbc') - Counter('bccd')
607 Counter({'b': 2, 'a': 1})
610 if not isinstance(other, Counter):
612 result = Counter()
625 >>> Counter('abbb') | Counter('bcc')
626 Counter({'b': 3, 'c': 2, 'a': 1})
629 if not isinstance(other, Counter):
631 result = Counter()
645 >>> Counter('abbb') & Counter('bcc')
646 Counter({'b': 1})
649 if not isinstance(other, Counter):
651 result = Counter()