A Report Card for Every Depot

Data with PythonMedium+20 XP+20

A Report Card for Every Depot

A courier firm logs every parcel: the depot it left from and how many minutes it took to deliver. The scanners at some depots glitch, so a few times are missing — stored as None.

The manager wants exactly the report that split–summarise–combine gives in pandas:

but it has to run on a machine without pandas.

Task: write depot_report(depots, minutes). The two lists have the same length, and row i of the log is depots[i] with minutes[i]. Return a list of tuples (depot, total, mean, count), one per depot, behaving the way pandas does:

  • There is one tuple for every depot that appears in depots, sorted alphabetically by depot name — pandas lists its groups in sorted order.
  • Missing times (None) are skipped: they add nothing to total, aren't counted in count, and aren't part of the mean.
  • total and mean are floats rounded to 4 decimal places; count is an int.
  • A depot whose times are all missing still gets its tuple, with total 0.0, count 0 and mean None — there is nothing to average.
  • Empty lists give an empty list.

Examples

depots = ['North', 'East', 'North', 'West', 'East', 'North']
minutes = [32, 41, 28, 55, 39, 30]
returns [('East', 80.0, 40.0, 2), ('North', 90.0, 30.0, 3), ('West', 55.0, 55.0, 1)]
depots = ['Leeds', 'Hull', 'Leeds', 'Hull', 'Leeds']
minutes = [18.5, None, 21.0, 26.0, None]
returns [('Hull', 26.0, 26.0, 1), ('Leeds', 39.5, 19.75, 2)]

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