Created
July 20, 2019 02:42
-
-
Save peketamin/2aa52e7220071d59e3bb6d616d2214fd to your computer and use it in GitHub Desktop.
Cumulative sum in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum(l: list): | |
if not l: | |
return 0 | |
i = l.pop() | |
return sum(l) + i | |
print(sum([1,2,3,4,5])) | |
# 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pythonで再帰のシンプルな例。スタックは100がデフォルトらしい