runtime
158 / 500
question 158 Collections & Itertools · medium

Passing and failing periods of a build

A repository's nightly build is either passing or failing. The status page summarises the history as periods: *passing from March 3 to March 4, failing from March 5 to March 6…*. Write build_periods(builds): return one (status, first_date, last_date) tuple per run of consecutive builds with the same status.

Functionbuild_periods(builds)
buildsa list of dictionaries with date (YYYY-MM-DD) and status, already in date order
Returnsa list of (status, first_date, last_date) tuples in date order; a one-day period has the same first and last date
Examples
callbuild_periods([{'date': '2025-03-03', 'status': 'passing'}, {'date': '2025-03-04', 'status': 'passing'}, {'date': '2025-03-05', 'status': 'failing'}, {'date': '2025-03-06', 'status': 'failing'}, {'date': '2025-03-07', 'status': 'passing'}])returns[('passing', '2025-03-03', '2025-03-04'), ('failing', '2025-03-05', '2025-03-06'), ('passing', '2025-03-07', '2025-03-07')]
callbuild_periods([{'date': '2025-03-10', 'status': 'failing'}, {'date': '2025-03-11', 'status': 'passing'}])returns[('failing', '2025-03-10', '2025-03-10'), ('passing', '2025-03-11', '2025-03-11')]
callbuild_periods([])returns[]

Loading your progress…

Passing and failing periods of a build — Python practice · Runtime