Python 3.8+statisticsfunction
statistics.multimode
mode
A list of all modes (values with the highest frequency).
Syntax
statistics.multimode(data)
Added in 3.8 as the tie-safe counterpart of mode: ties are fine and empty input yields [] instead of the StatisticsError that mode raises. Watch the flip side — when every value occurs equally often you get all of them back, which means "no mode at all" rather than a list of meaningful ones; the order follows first appearance.
Examples
import statistics
print(statistics.multimode([1, 1, 2, 2, 3])) # → [1, 2]
print(statistics.multimode('aabbbcc')) # → ['b']
print(statistics.multimode([1, 2, 3])) # → [1, 2, 3]
print(statistics.multimode([])) # → []
print(statistics.mode([1, 1, 2, 2, 3])) # → 1
See also
Open in the full glossarydocs.python.orgReport an inaccuracy