Skip to content

Instantly share code, notes, and snippets.

@peketamin
Created July 20, 2019 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peketamin/2aa52e7220071d59e3bb6d616d2214fd to your computer and use it in GitHub Desktop.
Save peketamin/2aa52e7220071d59e3bb6d616d2214fd to your computer and use it in GitHub Desktop.
Cumulative sum in Python
def sum(l: list):
if not l:
return 0
i = l.pop()
return sum(l) + i
print(sum([1,2,3,4,5]))
# 15
@peketamin
Copy link
Author

Pythonで再帰のシンプルな例。スタックは100がデフォルトらしい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment