Skip to content

Instantly share code, notes, and snippets.

@sumancbd
sumancbd / memoize.py
Last active June 30, 2026 13:57
Python Interview Question: Memoize Function Using Closure (supports multiple args + mutable inputs like lists/dicts)
"""
Python Coding Question: Memoize Function Using Closure
======================================================
You are given a function. Write another function called `memoize` that can wrap
any function and cache its result.
If the wrapped function is called again with the same input, it should return
the cached result instead of executing the original function again.