Join Data from Two Endpoints

Medium ⏱ 12 min 61% acceptance ★★★★★ 4.6
Write orders_with_names(api) where api is a base URL: GET /orders (list of {id, user_id, amount}) and /users (list of {id, name}), then return the orders enriched with a user_name field by joining on user_id — build a user-id → name dict first, don't nest loops.

Examples

Example 1
Input
orders_with_names(base)
Output
orders each carrying user_name
Explanation

A dict lookup joins the two payloads in O(n).

Constraints

  • Exactly two HTTP calls.
  • Unknown user_ids get user_name None.

Topics

APIsdata joining

Companies

UberSwiggyOla

Hints

Hint 1

users_by_id = {u["id"]: u["name"] for u in users}.

Hint 2

Enrich with dict unpacking or item assignment.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.