Write a program using function called cumulative_sum that takes a list of numbers and returns the cumulative sum; that is, a new list where the nth element is the sum of the first n elements from the original list. For example, the cumulative sum of [1, 2, 3] is [1, 3, 6].
def camulative_sum(lst:list):
res = list()
sum = 0
for item in lst:
sum += item
res.append(sum)
return res
Comments
Leave a comment