Skip to content

Instantly share code, notes, and snippets.

@svalleru
Last active October 16, 2015 19:39
Show Gist options
  • Save svalleru/f468a96906dd98e55233 to your computer and use it in GitHub Desktop.
Save svalleru/f468a96906dd98e55233 to your computer and use it in GitHub Desktop.
RecursiveSum
#Calculate sum of the elements in a list 'recirsively'
def listsum(numList):
if len(numList) == 1:
return numList[0]
else:
return numList[0] + listsum(numList[1:])
print(listsum([1,3,5,7,9]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment