Your question is Edge Cases and Tenfold Scale. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
Odeko turns each day's coffee shop orders into purchase orders sent to suppliers. Here is the function that rolls up every café's line items into per-supplier case counts.
def build_purchase_orders(daily_orders, supplier_catalog):
purchase_orders = {}
for order in daily_orders:
for line in order["items"]:
sku = line["sku"]
quantity = line["quantity"]
supplier = None
for catalog_entry in supplier_catalog:
if catalog_entry["sku"] == sku:
supplier = catalog_entry["supplier"]
break
if supplier not in purchase_orders:
purchase_orders[supplier] = {}
if sku not in purchase_orders[supplier]:
purchase_orders[supplier][sku] = 0
purchase_orders[supplier][sku] += quantity
for supplier, skus in purchase_orders.items():
for sku, total in skus.items():
case_size = 12
skus[sku] = total // case_size
return purchase_orders
How does this solution handle edge cases, and how would you scale this implementation if the number of cafés and daily orders increased tenfold? Walk through what you would check for and what you would change.