Skip to main content
edited body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Hereby another 'Pythonic' variant of Jamal & MatthewsMatthew's answer which does not require the use of both range() & len()range() and len():

[sum(L[:i[0]+1]) for i in enumerate(L)]

enumerateenumerate is handy to use since it creates tuples containing the index and value at that index.

Hereby another 'Pythonic' variant of Jamal & Matthews answer which does not require the use of both range() & len():

[sum(L[:i[0]+1]) for i in enumerate(L)]

enumerate is handy to use since it creates tuples containing the index and value at that index.

Hereby another 'Pythonic' variant of Matthew's answer which does not require the use of both range() and len():

[sum(L[:i[0]+1]) for i in enumerate(L)]

enumerate is handy to use since it creates tuples containing the index and value at that index.

Source Link

Hereby another 'Pythonic' variant of Jamal & Matthews answer which does not require the use of both range() & len():

[sum(L[:i[0]+1]) for i in enumerate(L)]

enumerate is handy to use since it creates tuples containing the index and value at that index.