Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Group orders by customer and status

Python data engineering interview problem. Difficulty: intermediate. Pattern: Dictionaries. About 15 minutes. Part of the Pro drill bank.

Ops wants open vs shipped orders grouped by customer so a dashboard can show each customer's workload by status.

Group orders by customer and status.

Requirements

  • The group key is the pair (customer, status) unless the tests use a nested dict.
  • Every order belongs to exactly one group.

Constraints

  • orders: records with customer and status fields.
  • A customer can have several statuses.

Examples

Input: group_orders([{'customer_id': 'U1', 'status': 'paid', 'order_id': 'A'}, {'customer_id': 'U1', 'status': 'paid', 'order_id': 'B'}, {'customer_id': 'U2', 'status': 'pending', 'order_id': 'C'}]) Output: {'U1': {'paid': ['A', 'B']}, 'U2': {'pending': ['C']}} This input follows the stated rules and produces this output.

Topics: lakebench, python, grouping.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Group orders by customer and status

Interview-style drill: Group a flat list of orders into a nested dictionary keyed by customer, then status.

Group orders by customer and status.