Finishers in Each Band

Data with PythonMedium+10 XP+10

Finishers in Each Band

A fun run puts every finisher into a time band for the results page.

times holds every finishing time, in minutes. edges is a list of at least two numbers, smallest first, that marks where the bands start and stop. Band 0 runs from edges[0] to edges[1], band 1 from edges[1] to edges[2], and so on.

A time belongs to a band when it is at least the band's first edge and less than its second edge. So a time exactly on an edge goes into the band that starts there.

Task: write band_counts(times, edges) and return how many finishers fall in each band, as a plain list in band order.

  • Times below the first edge, or at or above the last edge, are not in any band. Don't count them.
  • A band with nobody in it gets a count of 0.
  • There is always at least one time.

Examples

times = [24.5, 31.0, 28.2, 40.1, 35.0, 22.9]
edges = [20, 30, 40, 50]
returns [3, 2, 1]
times = [18, 25, 30, 45, 60]
edges = [20, 30, 40]
returns [1, 1]

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