Last active
June 25, 2019 09:47
-
-
Save louisswarren/06522b569043db4be10eccb9edf36b78 to your computer and use it in GitHub Desktop.
Logging in python, because mutable default arguments is a feature
This file contains hidden or 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 log(x=None, acc=[]): | |
if x is None: | |
print('\n'.join(acc)) | |
else: | |
acc.append(x) | |
log("Hello") | |
log("Goodbye") | |
log() |
This file contains hidden or 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 fib(n, _mem=[1, 1]): | |
for i in range(len(_mem), n + 1): | |
_mem.append(_mem[-2] + _mem[-1]) | |
return _mem[n] | |
for i in range(10): | |
print(fib(i)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment