runtime
76 / 500
question 76 Dictionaries & Sets · medium

The new warehouse empties the old one

A shop is opening a new warehouse. It should stock every product the Atlanta warehouse lists, starting at 0 units, and then receive its first delivery. A delivery line for a product that isn't in the catalogue must be reported as skipped <id> and not stored. Then every warehouse is printed. The program stops with a KeyError, and once that is fixed you'll find that opening the new warehouse also wipes out Atlanta's stock. Fix both bugs.

Inputsstock, a dictionary from warehouse to its own stock dictionary; new_site; delivery, a list of (product_id, units)
Printsskipped <id> for each unknown delivery line, in delivery order, then <warehouse> <stock dictionary> for every warehouse
Must notchange the Atlanta or Denver stock
Examplesthe starter's data prints skipped P0999, then Atlanta and Denver unchanged, then Boise {'P0035': 0, 'P0146': 5}
Expected output4 lines
  1. 1skipped P0999
  2. 2Atlanta {'P0035': 4, 'P0146': 9}
  3. 3Denver {'P0035': 12, 'P0146': 0}
  4. 4Boise {'P0035': 0, 'P0146': 5}

Loading your progress…

The new warehouse empties the old one — Python practice · Runtime