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

21st Nov 2016, 12:39 PM
Onkar Ashok Gumate
Onkar Ashok Gumate - avatar
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?
22nd Nov 2016, 12:28 AM
Kirk Schafer
Kirk Schafer - avatar
0
Sorry, didn't get the question. Could you rephrase it
21st Nov 2016, 4:24 PM
donkeyhot
donkeyhot - avatar
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
10th Jan 2017, 4:50 AM
Renata
0
Thank you so much
13th Feb 2019, 11:57 AM
Onkar Ashok Gumate
Onkar Ashok Gumate - avatar