0
Can someone pls explain what does ACCUMULATE actually do?
1 Answer
+ 1
if you run this code:
import itertools
list = [1,2,3,4,5]
for sum in itertools.accumulate(list):
  print(sum)
you will get:
1
3
6
10
15
as output. so accumulate will get you sums of the list up to each element. sum up to first element is 1, up to second is 1+2=3, up to third is 1+2+3=6, and so on. you can also specify some other operation instead of addition. more about function here https://docs.python.org/3.3/library/itertools.html#itertools.accumulate