memoize(func) caching results in a dict keyed by the positional arguments tuple — repeat calls with the same args skip the computation. Then note in discussion that functools.lru_cache is the production version (bounded, thread-aware).@memoize on slow_square; slow_square(4); slow_square(4)
16 both times, computed once
The second call was a dict hit.
if args in cache: return cache[args].
Store before returning.