Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Last active June 25, 2019 09:47
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 louisswarren/06522b569043db4be10eccb9edf36b78 to your computer and use it in GitHub Desktop.
Save louisswarren/06522b569043db4be10eccb9edf36b78 to your computer and use it in GitHub Desktop.
Logging in python, because mutable default arguments is a feature
def log(x=None, acc=[]):
if x is None:
print('\n'.join(acc))
else:
acc.append(x)
log("Hello")
log("Goodbye")
log()
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