3 ms·
I'm a Python veteran, and, if you do it like this, I'll shoot you. Add a @memoize decorator and do it there, you need to always be as obvious as possible. Comp
by StavrosK 15y ago
I'm a Python veteran, and, if you do it like this, I'll shoot you.
Add a @memoize decorator and do it there, you need to always be as obvious as possible. Compare:
@memoize
def fibonacci(n): pass
def fibonacci(n, memory=[]): pass
You don't even need documentation for the first example.
- paulmcpazzi 15y agoStarting from Python 3.2 there is a builtin decorator: http://docs.python.org/dev/library/functools.html#functools.lru_cache http://docs.python.org/dev/library/functools.html#functools....
- StavrosK 15y agoThat's fantastic, thanks for the link.