Show the mutable default argument bug: write a function add_to(item, bag=None) that safely creates a
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
Problem
Show the mutable default argument bug: write a function add_to(item, bag=None) that safely creates a new dict if bag is None. Call it twice with 'a' and 'b'. Print each result to show they are independent.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.