3 ms·
I don't know if that's a helpful framing? def sum(arr): total = 0 for x in arr: total += x return total and def sum(ar
by alecbz 4y ago
I don't know if that's a helpful framing?
def sum(arr):
total = 0
for x in arr:
total += x
return total
and
def sum(arr):
if len(arr) == 0:
return 0
return arr[0] + sum(arr[1:])
both operate over an array but I'd call one of them recursive and the other iterative.