mirror of
https://github.com/python/cpython.git
synced 2025-10-07 23:51:16 +00:00
bpo-45851: Avoid full sort in statistics.multimode() (#29662)
Suggested by Stefan Pochmann.
This commit is contained in:
parent
ef5305819f
commit
04e03f496c
1 changed files with 5 additions and 3 deletions
|
@ -609,9 +609,11 @@ def multimode(data):
|
|||
>>> multimode('')
|
||||
[]
|
||||
"""
|
||||
counts = Counter(iter(data)).most_common()
|
||||
maxcount, mode_items = next(groupby(counts, key=itemgetter(1)), (0, []))
|
||||
return list(map(itemgetter(0), mode_items))
|
||||
counts = Counter(iter(data))
|
||||
if not counts:
|
||||
return []
|
||||
maxcount = max(counts.values())
|
||||
return [value for value, count in counts.items() if count == maxcount]
|
||||
|
||||
|
||||
# Notes on methods for computing quantiles
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue