Skip to content

Instantly share code, notes, and snippets.

@nicholaskajoh
Created November 9, 2016 13:30
Show Gist options
  • Save nicholaskajoh/1cf2e209f7a04e45d3d0a40cff5be9c1 to your computer and use it in GitHub Desktop.
Save nicholaskajoh/1cf2e209f7a04e45d3d0a40cff5be9c1 to your computer and use it in GitHub Desktop.
# Get the sum of a list of numbers without using a for loop
def add(arr, s = 0):
s += arr[0]
if len(arr) > 1:
s += add(arr[1:])
return s
print("Sum", add([1, 2, 3, 4, 5]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment