diff options
author | Raymond Hettinger <python@rcn.com> | 2010-04-03 10:22:00 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-04-03 10:22:00 (GMT) |
commit | 34c35b2788f4f764022f11a624fb08d325c31e94 (patch) | |
tree | 69659df9223549ce681e931048c4bd38c2aab980 /Doc | |
parent | f70c5810565728b29a375492d5c3a37c5aa9af91 (diff) | |
download | cpython-34c35b2788f4f764022f11a624fb08d325c31e94.zip cpython-34c35b2788f4f764022f11a624fb08d325c31e94.tar.gz cpython-34c35b2788f4f764022f11a624fb08d325c31e94.tar.bz2 |
Add subtract() method to collections.Counter() objects.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/collections.rst | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index a3bbc63..5a6f0de 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -230,6 +230,17 @@ For example:: >>> Counter('abracadabra').most_common(3) [('a', 5), ('r', 2), ('b', 2)] + .. method:: subtract([iterable-or-mapping]) + + Elements are subtracted from an *iterable* or from another *mapping* + (or counter). Like :meth:`dict.update` but subtracts counts instead + of replacing them. Both inputs and outputs may be zero or negative. + + >>> c = Counter(a=4, b=2, c=0, d=-2) + >>> d = Counter(a=1, b=2, c=3, d=4) + >>> c.subtract(d) + Counter({'a': 3, 'b': 0, 'c': -3, 'd': -6}) + The usual dictionary methods are available for :class:`Counter` objects except for two which work differently for counters. |