Mode of a List

Probability and StatisticsEasy+10 XP+10

Mode of a List

The mode is the value that shows up the most times. Unlike the mean and median, it's about how often a value appears, not how big it is.

Task: write mode(values) returning the most frequent value, rounded to 4 decimal places.

Ties need a rule, so here it is:

  • If several values are tied for most frequent, return the smallest of them.
  • When every value appears exactly once, they are all tied — so the mode is the smallest value in the list.

Also worth knowing:

  • values is never empty, and it arrives in no particular order.
  • Values may be whole or decimal, and decimals count as repeats only when they match exactly.

So the job is really two steps: count how often each value appears, then pick a winner from the ones that share the highest count.

Mode Explorer

Discover the most frequently occurring observations in a dataset.

Frequency Builder
Raw Observations:

Examples

values = [3, 1, 4, 1, 5]
returns 1.0
values = [7, 2, 9, 4]
returns 2.0

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run