itertools.accumulate()
to create the accumulated sum for each element.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]
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️