I am trying to write a function that displays elements of a list in order to get the sum of an element and previous elements in a list in a functional style using python, for example:
func([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) = [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]
I tried using recursion, but I get RuntimeError: maximum recursion depth exceeded with a long list .:
def recursion_way(inlist, accu, summ): if len(inlist) == 0: return accu else: return recursion_way(inlist[1:], accu + [summ + inlist[0]], summ + inlist[0])
source share