Quiz 2
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

python
def 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)]
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.