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)
new_list.append(rec[-1]+last)
return last+rec
tests = [[],
[1],
[1,2],
[1,2,3],
[1,2,1,3]]
for t in tests:
print(rec_cumsum(t))
CmRlZiByZWNfY3Vtc3VtKG51bWJlcnMpOgogICAgJycnIElucHV0OiBudW1iZXJzIC0gYSBsaXN0IG9mIG51bWJlcnMsCiAgICAgICAgICAgIE91dHB1dDogYSBsaXN0IG9mIGN1bXVsYXRpdmUgc3VtcyBvZiB0aGUgbnVtYmVycycnJwogICAgaWYgbGVuKG51bWJlcnMpIDw9IDE6CiAgICAgICAgIHJldHVybiBudW1iZXJzCiAgICBuZXdfbGlzdD1udW1iZXJzCiAgICBsYXN0PW5ld19saXN0Wy0xXQogICAgbmV3X2xpc3QucmVtb3ZlKGxhc3QpCiAgICByZWMgPSByZWNfY3Vtc3VtKG5ld19saXN0KQogICAgbmV3X2xpc3QuYXBwZW5kKHJlY1stMV0rbGFzdCkKICAgIHJldHVybiBsYXN0K3JlYwoKdGVzdHMgPSBbW10sCiAgICAgICAgIFsxXSwKICAgICAgICAgWzEsMl0sCiAgICAgICAgIFsxLDIsM10sCiAgICAgICAgIFsxLDIsMSwzXV0KZm9yIHQgaW4gdGVzdHM6CiAgICBwcmludChyZWNfY3Vtc3VtKHQpKQo=