mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-25478: Add total() method to collections.Counter (GH-25829)
This commit is contained in:
parent
d52bbde942
commit
8c598dbb94
4 changed files with 21 additions and 1 deletions
|
@ -581,6 +581,10 @@ class Counter(dict):
|
|||
# Needed so that self[missing_item] does not raise KeyError
|
||||
return 0
|
||||
|
||||
def total(self):
|
||||
'Sum of the counts'
|
||||
return sum(self.values())
|
||||
|
||||
def most_common(self, n=None):
|
||||
'''List the n most common elements and their counts from the most
|
||||
common to the least. If n is None, then list all element counts.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue