0

i have got a list like this in Python:

List [1, 41, 6, 1, 41, 13]

now i want to add the elements and want to write it in a new list like this:

newList [42, 48, 49, 90, 103]

i hope someone can help me

thanks

Nekoso
  • 113
  • 5

1 Answers1

0

With numpy.cumsum:

>>> import numpy as np
>>> lst = [1, 41, 6, 1, 41, 13]
>>> list(np.cumsum(lst)[1:])
[42, 48, 49, 90, 103]
timgeb
  • 76,762
  • 20
  • 123
  • 145