Editor

Day-to-Day Changes

#505 · Lists · Beginner · 25 XP · about 4 min

A weather station writes down one reading a day. Write daily_changes(readings) that returns how much each reading changed from the day before: the second reading minus the first, then the third minus the second, and so on.

A list of n readings gives n - 1 changes, so a list with fewer than two readings gives an empty list.

Examples

daily_changes([20, 23, 21, 21])  # returns [3, -2, 0]
daily_changes([5, 10])           # returns [5]
daily_changes([7])               # returns []

In the first example the reading went up by 3, then down by 2, then stayed the same.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.