Too Far From the Middle

Data with PythonMedium+10 XP+10

Too Far From the Middle

A takeaway logs how many minutes each delivery took. Some entries are None because the driver forgot to log the time.

Write outliers(minutes). Using the 1.5 × IQR rule, return the times that fall outside the fences, in the order they appear in the list:

  • Q1 and Q3 are the 0.25 and 0.75 quantiles from pandas quantile, worked out from the logged times only (skip the Nones)
  • low fence = Q1 − 1.5 × IQR, high fence = Q3 + 1.5 × IQR
  • a time is an outlier if it is strictly below the low fence or strictly above the high fence

Keep repeated outliers each time they appear. Never include a None. If nothing is outside the fences, return an empty list. There is always at least one logged time.

Examples

minutes = [12, 14, 15, 15, 16, 18, 19, 21, 95]
returns [95.0]
minutes = [20, None, 22, 2, 21, 23, None, 60, 22]
returns [2.0, 60.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