Reference · Statistics

stats.multimode

signature
stats.multimode(list | null) -> list

What 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

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 str

Chaining

let scores = [72, 85, 90, 66, 85, 78]print(scores | stats.multimode)print(scores | stats.multimode | len)
output
[85]1

See also

stats.mode, unique, count

Thread
7Useful? Like it, or add to its thread below.

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