Checkpoint

Checkpoint: Market Day Ledger

The Guild runs a lantern-oil stall on market days. The cashier keeps a CSV, with British-style dates (day/month/year) and stray spaces:

day, item, price
20/11/2026, oil, 4.10
20/11/2026, wick ,0.75
21/11/2026,oil, 4.10

The treasurer wants exact totals per day and the best-selling item, sent as JSON. This checkpoint uses csv, datetime, Decimal, Counter and json together.

Assignment

  1. load_sales(text) reads the CSV and returns a list of dicts like {"day": date(2026, 11, 20), "item": "oil", "price": Decimal("4.10")}. Strip spaces from keys and values. day is a date (not a datetime) and price is a Decimal made from the string.
  2. summary(sales) returns a JSON string for a dict with two keys:
    • "best_seller": the most common item name;
    • "days": a dict mapping each ISO date string ("2026-11-20") to that day's total as a string ("4.85").