Fix the duplicate filter for incoming order ids

Review the AI's codeEasy10 min

Your task

Your order import drops duplicate orders before it writes them. The first version was a JavaScript filter whose callback forgot return true on the keep path, so it dropped every order. Some upstream systems also send orders with no id at all, as an empty string.

An assistant wrote dedupe_ids(order_ids). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • order_ids: the ids of the incoming orders, in arrival order.
  • Return the ids to keep, in arrival order.

Rules the tests check:

  • Keep the first order with each id and drop every later order with the same id.
  • Ids compare exactly: case and spaces matter, so A and a are different ids, and so are 1 and 01.
  • An empty id "" means the id is missing. Two missing ids are not evidence of a duplicate, so keep every order with an empty id.

Examples

dedupe_ids(order_ids: list[str]) -> list[str]
Example 1
Inputdedupe_ids(["a", "b", "a", "c"])
Output["a", "b", "c"]
Example 2
Inputdedupe_ids(["a", "a", "a"])
Output["a"]
Example 3
Inputdedupe_ids(["x", "y", "z"])
Output["x", "y", "z"]