from itertools import accumulate, takewhile nums = list(accumulate(range(9))) | Sololearn: Learn to code for FREE!

+1

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

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

2/26/2018 6:39:14 AM

Ankush

2 Answers

New Answer

+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!

+1

Thanks!