0

Can someone pls explain what does ACCUMULATE actually do?

19th Jul 2016, 4:27 PM
Kajal Piwal
Kajal Piwal - avatar
1 Réponse
+ 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
27th Jul 2016, 7:59 AM
RedAnt
RedAnt - avatar