+ 1

from itertools import accumulate, takewhile nums = list(accumulate(range(9)))

How? Explain- output: [0, 1, 3, 6, 10, 15, 21, 28, 36]

26th Feb 2018, 6:39 AM
Ankush
Ankush - avatar
2 Answers
+ 3
The list consists of the accumulation. list[0]=0 list[1]=0+1 list[2]=0+1+2=3 list[3]=-0+1+2+3=6 and the life goes on. Hope that helped!
26th Feb 2018, 7:01 AM
Joshua Choi
Joshua Choi - avatar
+ 1
Thanks!
26th Feb 2018, 4:04 PM
Ankush
Ankush - avatar