Challenge 3: Fix the Mutable Default Bug — Possible Solution ==================================================================== def add_item(item, basket=None): if basket is None: basket = [] basket.append(item) return basket print(add_item("apple")) # ['apple'] print(add_item("banana")) # ['banana'] — a fresh, independent list this time WHY THIS WORKS AS AN ANSWER ------------------------------ The buggy version's problem, per the chapter's warn-box, is that basket=[] is evaluated exactly once when the function is defined, so every call that relies on the default ends up sharing and mutating that same one list across calls. The fix replaces the mutable default with an immutable one instead: basket=None. None is a single, immutable value that's perfectly safe to reuse as a default across every call, unlike a list. if basket is None: basket = [] then runs at the START of the function body, on every single call, not just once at definition time. So each call that doesn't supply its own basket gets a genuinely brand-new empty list created fresh right then — which is why add_item("banana") correctly returns ['banana'] instead of ['apple', 'banana'] the way the buggy version did. If a caller DOES pass their own basket explicitly, basket is None is False, so that provided list is used as-is and the fresh-list branch is skipped entirely — the fix only changes behavior for the default-omitted case, exactly as intended.