Skip to main content
1 of 3
Peilonrayz
  • 44.6k
  • 7
  • 80
  • 158

In Python 3 itertools gained a new function accumulate that does what you want. I'd recommend that you instead used this function. Or if you can't if you're in Python 2 to upgrade. This would single handedly change your code to:

from itertools import accumulate

new_l = accumulate(l)
Peilonrayz
  • 44.6k
  • 7
  • 80
  • 158