diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2021-05-03 03:19:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-03 03:19:51 (GMT) |
commit | 8c598dbb9483bcfcb88fc579ebf27821d8861465 (patch) | |
tree | 29555566ce3e45c830658aa7129a200088e1dcfa /Doc/library/collections.rst | |
parent | d52bbde9421987d216c600557ef5bc931d03efcc (diff) | |
download | cpython-8c598dbb9483bcfcb88fc579ebf27821d8861465.zip cpython-8c598dbb9483bcfcb88fc579ebf27821d8861465.tar.gz cpython-8c598dbb9483bcfcb88fc579ebf27821d8861465.tar.bz2 |
bpo-25478: Add total() method to collections.Counter (GH-25829)
Diffstat (limited to 'Doc/library/collections.rst')
-rw-r--r-- | Doc/library/collections.rst | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 723c9da..94166ec 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -313,6 +313,16 @@ For example:: .. versionadded:: 3.2 + .. method:: total() + + Compute the sum of the counts. + + >>> c = Counter(a=10, b=5, c=0) + >>> c.total() + 15 + + .. versionadded:: 3.10 + The usual dictionary methods are available for :class:`Counter` objects except for two which work differently for counters. @@ -342,7 +352,7 @@ All of those tests treat missing elements as having zero counts so that Common patterns for working with :class:`Counter` objects:: - sum(c.values()) # total of all counts + c.total() # total of all counts c.clear() # reset all counts list(c) # list unique elements set(c) # convert to a set |