Shallow copy, deep copy, and the nested-dict bug — step 9 of 9
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
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
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.