Reference · Statistics
stats.multimode
signature
stats.multimode(list | null) -> listWhat it does
Every most common value in a list, in the order each was first seen, as Python's
statistics.multimode. The values can be anything, not only numbers. Where
stats.mode picks the first of a tie, this gives the
whole tie.
Examples
print(stats.multimode([1, 1, 2, 2, 3]))print(stats.multimode(["b", "a", "b", "a"]))print(stats.multimode([1, 2, 2, 3]))output
[1, 2]["b", "a"][2]Edge cases
- No value repeated means every value is a mode, in the list's order.
- An empty list, or
null, gives[], not an error. 1and1.0are one value, and so are0.0and-0.0; the first seen is given.- Text
"1"and the number1are different values. - Lists and maps are compared by their contents.
print(stats.multimode([3, 1, 2]), stats.multimode([]), stats.multimode(null))print(stats.multimode([1.0, 1, 2]), stats.multimode([0.0, -0.0]), stats.multimode([1, "1", 1.0, "1"]))print(stats.multimode([[1, 2], [1, 2], [3]]))output
[3, 1, 2] [] [][1.0] [0.0] [1, "1"][[1, 2]]Errors
An argument that is not a list or null is a runtime error, not an error value.
this one fails
print(stats.multimode("aab"))output
line 1: `stats.multimode` expects a list as argument 1, got strChaining
let scores = [72, 85, 90, 66, 85, 78]print(scores | stats.multimode)print(scores | stats.multimode | len)output
[85]1See also
Thread
Thread 0 posts
On stats.multimode(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo