All problems
Seasonal Differences at Lag m
Problem
Compute the seasonal difference of a series at lag m, given by x[t] - x[t-m] for every t from m to n-1. Differencing at the seasonal lag removes a repeating pattern of period m.
Return an empty list when m is not positive or m is at least the length of the series.
Hint
With m = 1 this reduces to ordinary first differences.
Test cases
case 1
in: [[1,2,3,10,20,30],3]
expected: [9,18,27]
case 2
in: [[5,7,9],1]
expected: [2,2]
case 3
in: [[1,2],2]
expected: []
case 4
in: [[1,2,3],0]
expected: []
Starter codePython
def seasonal_differences(series, m):
# Your code here
pass4 test cases · run your code against them in the editor