Minimalistic Memoization (Python, 16 lines)
code.activestate.com
code.activestate.com
IMHO, code can be more pythonic and still minimalistic if we declare fib this way using decorators
@memoize fib(n)
also we don't need to use the line : fib = memoize(fib) after this change
I don't know though if decorators were not used on purpose..
Update: I have commented updated code on recipe's page - http://code.activestate.com/recipes/577219-minimalistic-memo...
Line 9: A formal parameter using the syntax * identifier receives a tuple containing any excess positional arguments.
Line 11: When the syntax * expression appears in the function call, expression evaluates to a sequence, the elements of which are treated as if they were the positional arguments.