Neural Sync Active
Synthetic 5 · Aggregate Inventory
Registry Synced
Synthetic 5 · Aggregate Inventory
82 words
1 min read
2026-08-02
Aggregate Inventory
Write
aggregate_inventory(records). Each record is (category, quantity). Return a list of (category, total) pairs sorted alphabetically by category. Repeated categories must be combined.Template Code
pythondef aggregate_inventory(records): pass
Public Tests
is_equal(aggregate_inventory([("pen", 3), ("book", 2), ("pen", 4)]), [("book", 2), ("pen", 7)])
is_equal(aggregate_inventory([]), [])
is_equal(aggregate_inventory([("cable", -1), ("cable", 5)]), [("cable", 4)])
MCQ
3 Unit Assessment
Reference-only archive item
The completed export preserved the prompt as an image but not a reusable answer key. The reconstruction below is for study, not scoring.
Study reconstruction
def aggregate_inventory(records):
totals = {}
for category, quantity in records:
totals[category] = totals.get(category, 0) + quantity
return [(category, totals[category]) for category in sorted(totals)]