runtime
311 / 500
question 311 Iterators & Generators · easy

Day-to-day temperature changes

A weather page shows how much each day's maximum temperature rose or fell compared with the day before. Write daily_changes(readings): return the list of differences between consecutive readings (today minus yesterday). readings may be a list or a generator reading a file, so use a single pass and no indexing.

Functiondaily_changes(readings)
readingsany iterable of numbers, in date order
Returnsa list with one difference per pair of neighbours; [] for fewer than two readings
Examples
calldaily_changes([31.7, 33.9, 30.6, 30.6])returns[2.2, -3.3, 0.0]
calldaily_changes([18.3, 19.4])returns[1.1]
calldaily_changes([-4.4, -12.2, -0.6])returns[-7.8, 11.6]

Loading your progress…

Day-to-day temperature changes — Python practice · Runtime