0

# how accumulate fun calculate total of running nos and of which nos

from itertools import accumulate, takewhile nums = list(accumulate(range(8))) print(nums) print(list(takewhile(lambda x: x<= 6, nums))) op: 0 1 3 6 10 15 21 28

4 Answers

+ 2

Assuming fun != party and Nos aren't the opposite of Yeses :) I think the question is:
How (does the) accumulate function calculate (the) running total (of numbers) and (how does it select which numbers to sum) or...what numbers is this example selecting?

0

Sorry, didn't get the question. Could you rephrase it

0

accumulate keeps the running total.
range(8) gives: 0 1 2 3 4 5 6 7
for each of those, let's keep the running (accumulated) total, showing how it is calculated:
accumulated
0 0
1 0+1=1
2 1+2=3
3 3+3=6
4 6+4=10
5 10+5=15
6 15+6=21
7 21+7=28

0

Thank you so much