Implement `memoize(fn)` as a decorator.
Return a wrapped version of fn that caches its results by positional args. Subsequent calls with identical args return from cache without calling fn.
Constraints
Only positional args; all args are hashable.
Example
@memoize
def fib(n):
return n if n < 2 else fib(n-1) + fib(n-2)
fib(30) # fast
25 points
~20 min
Recent Submissions
No submissions yet — hit Run Tests to try!
Hints
Use a dict inside the closure keyed on args tuple.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.
SponsoredReserved space — layout preview until AdSense is connected