Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Files

Latest commit

 

History

History
23 lines (18 loc) · 434 Bytes

cumsum.md

File metadata and controls

23 lines (18 loc) · 434 Bytes
title type tags cover dateModified
Partial sum list
snippet
list
digital-nomad-16
2021-01-13 23:30:41 +0200

Creates a list of partial sums.

  • Use itertools.accumulate() to create the accumulated sum for each element.
  • Use list() to convert the result into a list.
from itertools import accumulate

def cumsum(lst):
  return list(accumulate(lst))
cumsum(range(0, 15, 3)) # [0, 3, 9, 18, 30]