Inventory with Counter Arithmetic

easy
Unit 10 · Collections0/3 to milestone

collections.Counter supports +, -, & and |. Use it to implement:

  • restock(stock, delivery): combined counts
  • fulfil(stock, order): returns (remaining, shortages), where remaining is the stock left after taking as much of each item as possible, and shortages maps items to how many couldn't be supplied. Neither result contains zero or negative counts.
  • common_items(a, b): counts present in both (the minimum of each)

All arguments and return values are Counters.

#collections#dictionaries2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Inventory with Counter Arithmetic · TechGradify