0

I am trying to re-write this for loop into a function to make it applicable to different time series. It is pretty straightforward but for some reason there are errors with the function. The goal is to subtract the current value with its preceding one:

wabash
  • 617
  • 1
  • 11
  • Notice how in the code you started out with, it says `diff.append(value)`, and in the code you wrote for the function, it says `diff = diff.append(value)`? Why change that? – Karl Knechtel Nov 26 '20 at 16:43

1 Answers1

1

append doesn't return the modified list, it modifies it in place. This means that

diff = diff.append(value)

will be assigning None to diff, causing your problem.

You just need

diff.append(value)

as you had in the original loop.

Kemp
  • 2,802
  • 1
  • 14
  • 26