mutation — why your code mysteriously breaks9 / 9
shallow copy, deep copy, and the nested-dict bug
Checkpoint
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Last one. Cursor wrote apply_discount, a function that's supposed to
take a list of order dicts and a percent, and return a new list of
orders with the discount applied. The original orders should be unchanged.
Two bugs: it uses .copy() instead of deepcopy (so the inner dicts are
shared), and it returns the wrong variable.
Fix the function so the script prints:
original first price: 100
discounted first price: 90.0
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _