question 77 Dictionaries & Sets · medium
Apply a supplier's price feed
A supplier sends a feed of (product_id, price) pairs. Apply it to the shop's prices dictionary one line at a time and report what changed: <id>: <old> -> <new> for a price that changed, <id>: new at <price> for a product the shop didn't have. A line with the same price is not printed but counted. Finish with <n> unchanged, <m> products. All prices are printed with two decimals.
Inputs
prices, a dictionary from product ID to price; feed, a list of (product_id, price) tuplesPrintsone line per change or new product, in feed order; then
<n> unchanged, <m> products (the size of prices afterwards)Order mattersa product that appears twice in the feed is compared with the price the first line set
Examplesthe starter's data prints changes for P0208 and P0659,
P0164: new at 31.00, then 1 unchanged, 4 productsExpected output4 lines
- 1P0208: 66.49 -> 59.99
- 2P0164: new at 31.00
- 3P0659: 51.49 -> 54.99
- 41 unchanged, 4 products