Message407349
This is consistent with the docstrings of the methods:
---------------------------------------------------------------------
>>> help(Counter.__iadd__)
Help on function __iadd__ in module collections:
__iadd__(self, other)
Inplace add from another counter, keeping only positive counts.
>>> c = Counter('abbb')
>>> c += Counter('bcc')
>>> c
Counter({'b': 4, 'c': 2, 'a': 1})
>>> help(Counter.update)
Help on function update in module collections:
update(self, iterable=None, /, **kwds)
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.update(d) # add elements from another counter
>>> c['h'] # four 'h' in which, witch, and watch
4
---------------------------------------------------------------------
However, it seems Counter.__iadd__ is not mentioned at all at https://docs.python.org/3/library/collections.html#collections.Counter. I think there could be a doc update. |
|
Date |
User |
Action |
Args |
2021-11-30 03:29:37 | Dennis Sweeney | set | recipients:
+ Dennis Sweeney, crypdick |
2021-11-30 03:29:37 | Dennis Sweeney | set | messageid: <1638242977.11.0.668509080665.issue45936@roundup.psfhosted.org> |
2021-11-30 03:29:37 | Dennis Sweeney | link | issue45936 messages |
2021-11-30 03:29:36 | Dennis Sweeney | create | |
|