I would like to know how to find the nth term - (n-1)th term within a list. I know it should be very simple, but I'm just having trouble with application. So given the input of [0, 2, 4, 6, 5]
, the function should return [0, 2, 2, 2, -1]
. My solution (which doesn't work) is as follows:
def cost_to_diff (stocks):
for i in range(i+1):
stock[i] = stock[i] - stock[i-1]
print stock
Why doesn't this work as intended?