runtime
77 / 500
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.

Inputsprices, a dictionary from product ID to price; feed, a list of (product_id, price) tuples
Printsone 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 products
Expected output4 lines
  1. 1P0208: 66.49 -> 59.99
  2. 2P0164: new at 31.00
  3. 3P0659: 51.49 -> 54.99
  4. 41 unchanged, 4 products

Loading your progress…

Apply a supplier's price feed — Python practice · Runtime