MCPcopy Index your code
hub / github.com/RustPython/RustPython / update

Method update

Lib/collections/__init__.py:680–712  ·  view source on GitHub ↗

Like dict.update() but add counts instead of replacing them. Source can be an iterable, a dictionary, or another Counter instance. >>> c = Counter('which') >>> c.update('witch') # add elements from another iterable >>> d = Counter('watch') >>> c.up

(self, iterable=None, /, **kwds)

Source from the content-addressed store, hash-verified

678 'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
679
680 def update(self, iterable=None, /, **kwds):
681 '''Like dict.update() but add counts instead of replacing them.
682
683 Source can be an iterable, a dictionary, or another Counter instance.
684
685 >>> c = Counter('which')
686 >>> c.update('witch') # add elements from another iterable
687 >>> d = Counter('watch')
688 >>> c.update(d) # add elements from another counter
689 >>> c['h'] # four 'h' in which, witch, and watch
690 4
691
692 '''
693 # The regular dict.update() operation makes no sense here because the
694 # replace behavior results in some of the original untouched counts
695 # being mixed-in with all of the other counts for a mismash that
696 # doesn't have a straight-forward interpretation in most counting
697 # contexts. Instead, we implement straight-addition. Both the inputs
698 # and outputs are allowed to contain zero and negative counts.
699
700 if iterable is not None:
701 if isinstance(iterable, _collections_abc.Mapping):
702 if self:
703 self_get = self.get
704 for elem, count in iterable.items():
705 self[elem] = count + self_get(elem, 0)
706 else:
707 # fast path when counter is empty
708 super().update(iterable)
709 else:
710 _count_elements(self, iterable)
711 if kwds:
712 self.update(kwds)
713
714 def subtract(self, iterable=None, /, **kwds):
715 '''Like dict.update() but subtracts counts instead of replacing them.

Callers 15

__init__Method · 0.95
test_basicsMethod · 0.95
test_updateMethod · 0.95
test_copyingMethod · 0.95
__or__Method · 0.45
__ror__Method · 0.45
__ior__Method · 0.45
__or__Method · 0.45
__ror__Method · 0.45

Calls 4

isinstanceFunction · 0.85
superClass · 0.85
_count_elementsFunction · 0.85
itemsMethod · 0.45

Tested by 6

test_basicsMethod · 0.76
test_updateMethod · 0.76
test_copyingMethod · 0.76