runtime
197 / 500
question 197 CSV JSON & JSONL · medium

Orders per customer, as JSON

The customer-service app shows each customer's orders from a JSON file. Build that file from the orders CSV.

Functionorders_by_customer(src, dest)
srcCSV with columns order_id,customer_id,status,total
Writesdest: a JSON object from each customer ID to {"orders": [order IDs in file order], "spent": total of those orders}
Rulescancelled orders are left out entirely; a customer whose only orders were cancelled doesn't appear; spent is a number
Returnsthe number of customers written
Examples
callorders_by_customer('orders.csv', '_b0.json')returns4

Loading your progress…

Orders per customer, as JSON — Python practice · Runtime