MCPcopy Index your code
hub / github.com/python/cpython / multimode

Function multimode

Lib/statistics.py:497–515  ·  view source on GitHub ↗

Return a list of the most frequently occurring values. Will return more than one result if there are multiple modes or an empty list if *data* is empty. >>> multimode('aabbbbbbbbcc') ['b'] >>> multimode('aabbbbccddddeeffffgg') ['b', 'd', 'f'] >>> multimode('') []

(data)

Source from the content-addressed store, hash-verified

495
496
497def multimode(data):
498 """Return a list of the most frequently occurring values.
499
500 Will return more than one result if there are multiple modes
501 or an empty list if *data* is empty.
502
503 >>> multimode('aabbbbbbbbcc')
504 ['b']
505 >>> multimode('aabbbbccddddeeffffgg')
506 ['b', 'd', 'f']
507 >>> multimode('')
508 []
509
510 """
511 counts = Counter(iter(data))
512 if not counts:
513 return []
514 maxcount = max(counts.values())
515 return [value for value, count in counts.items() if count == maxcount]
516
517
518## Measures of spread ######################################################

Callers 1

test_basicsMethod · 0.85

Calls 3

CounterClass · 0.90
valuesMethod · 0.45
itemsMethod · 0.45

Tested by 1

test_basicsMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…