Skip to content
DeepForgeby svx
All problems
EasyStatisticsst-013

Difference Series

Problem

Return the consecutive differences data[i] - data[i-1] for i from 1 to n-1, so the result has length n-1. Return an empty list if data has fewer than two elements.

Hint

Pair each element with the previous one and subtract.

Test cases

case 1
in: [[1,3,6,10]]
expected: [2,3,4]
case 2
in: [[5]]
expected: []
case 3
in: [[4,2,2]]
expected: [-2,0]
case 4
in: [[1,2.5,2]]
expected: [1.5,-0.5]
case 5
in: [[0,0,0]]
expected: [0,0]
Starter codePython
def differences(data):
    # Your code here
    pass

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