question 255 Classes & Objects · medium
Price changes that share what didn't change
A pricing tool previews next month's catalogue. Copying 50,000 products to change 30 prices is wasteful, so: write apply_price_changes(products, changes) that returns a new list in which each changed product is a new object with the new price, and every unchanged product is the very same object as before. The original products must keep their prices.
Function
apply_price_changes(products, changes)productsa list of
Product objects (sku, name, price)changesa dictionary from SKU to new price; SKUs not in the catalogue are ignored
Returnsa new list, same order: new objects for changed products, the original objects for the rest
Notea change to the price a product already has is not a change: keep that object