Q29: How does @functools.lru_cache implement memoization?

@functools.lru_cache(maxsize=128) wraps functions with a Least Recently Used (LRU) Cache hash table. Calls with identical arguments return cached results instantly ($O(1)$), bypassing computation overhead.

Key Takeaways
  • Memoizes function call results using an internal dictionary.
  • Arguments passed to cached functions MUST be hashable.
Knowledge Check

What happens if you pass a mutable list argument to a function decorated with @functools.lru_cache?