Partial sum list

Python, List · Jan 13, 2021

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]

More like this

  • Filter non-unique list values

    Creates a list with the non-unique values filtered out.

    Python, List · Nov 2, 2020

  • Filter unique list values

    Creates a list with the unique values filtered out.

    Python, List · Nov 2, 2020

  • Value frequencies

    Creates a dictionary with the unique values of a list as keys and their frequencies as the values.

    Python, List · Nov 2, 2020