Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-002

First Difference Series

Problem

Return the first differences of a series as a list: [x[1] - x[0], x[2] - x[1], ...].

A series with fewer than two elements produces an empty list. This is the basic operation that removes a linear trend.

Hint

Loop over adjacent index pairs.

Test cases

case 1
in: [[1,3,6,10]]
expected: [2,3,4]
case 2
in: [[5]]
expected: []
case 3
in: [[0,-2,0]]
expected: [-2,2]
case 4
in: [[2,2]]
expected: [0]
Starter codePython
def first_differences(series):
    # Your code here
    pass

4 test cases · run your code against them in the editor