Define memoize(fn) that returns a wrapper using a dict cache keyed by the args tuple
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
Problem
Define memoize(fn) that returns a wrapper using a dict cache keyed by the args tuple. Decorate a function slow_square(n) that returns n * n. Print slow_square(4), then slow_square(4) again (the second call hits the cache). Expected output is 16 on both lines.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.