def cumulative_sum(L): retL = [] sum = 0 for e in L: sum += e retL.append(sum) return retL L = [1,2,3] print cumulative_sum(L)