def rec_cumsum(numbers):
''' Input: numbers - a list of numbers,
Output: a list of cumulative sums of the numbers'''
if len(numbers) <= 1:
return numbers
new_list=numbers
last=new_list[-1]
new_list.remove(last)
rec = rec_cumsum(new_list)
rec.append(rec[-1]+last)
return rec
tests = [[],
[1],
[1,2],
[1,2,3],
[1,2,1,3]]
for t in tests:
print(rec_cumsum(t))
ZGVmIHJlY19jdW1zdW0obnVtYmVycyk6CiAgICAnJycgSW5wdXQ6IG51bWJlcnMgLSBhIGxpc3Qgb2YgbnVtYmVycywKICAgICAgICAgICAgT3V0cHV0OiBhIGxpc3Qgb2YgY3VtdWxhdGl2ZSBzdW1zIG9mIHRoZSBudW1iZXJzJycnCiAgICBpZiBsZW4obnVtYmVycykgPD0gMToKICAgICAgICAgcmV0dXJuIG51bWJlcnMKICAgIG5ld19saXN0PW51bWJlcnMKICAgIGxhc3Q9bmV3X2xpc3RbLTFdCiAgICBuZXdfbGlzdC5yZW1vdmUobGFzdCkKICAgIHJlYyA9IHJlY19jdW1zdW0obmV3X2xpc3QpCiAgICByZWMuYXBwZW5kKHJlY1stMV0rbGFzdCkKICAgIHJldHVybiByZWMKCnRlc3RzID0gW1tdLAogICAgICAgICBbMV0sCiAgICAgICAgIFsxLDJdLAogICAgICAgICBbMSwyLDNdLAogICAgICAgICBbMSwyLDEsM11dCmZvciB0IGluIHRlc3RzOgogICAgcHJpbnQocmVjX2N1bXN1bSh0KSkKCgo=