All problems
Lag Operator Value
Problem
The lag operator L moves a series back in time: applying L^k to x[t] gives x[t-k]. Given the series, an index t, and a non-negative lag k, return the value x[t-k].
If the lagged index falls outside the series, return None.
Hint
Guard the shifted index before indexing to avoid Python's negative wraparound.
Test cases
case 1
in: [[10,20,30,40],3,1]
expected: 30
case 2
in: [[10,20,30],2,2]
expected: 10
case 3
in: [[1,2,3],0,1]
expected: null
case 4
in: [[5,6,7],1,0]
expected: 6
Starter codePython
def lag_value(series, t, k):
# Your code here
pass4 test cases · run your code against them in the editor