Back to Practice
#0001

Remove Duplicates Without Losing Order

EasyPython10 min10 XP

Problem

Given a list of values, return a new list that contains each value only once, keeping the order of first appearance.

Why This Matters

This tiny problem tests whether you understand the difference between a set as a membership helper and a list as an ordered result.

Function Signature

def unique_in_order(items):

Examples

Example 1
Inputitems = ["ml", "sql", "ml", "python", "sql"]
Output["ml", "sql", "python"]

"ml" and "sql" repeat later, but only their first appearances are kept.

Constraints

  • The input list can be empty.
  • Items are hashable values such as strings, numbers, or tuples.
  • Do not sort the result.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 4 hidden categories
Mixed repeated strings
Input["ml", "sql", "ml", "python", "sql"]
Expected["ml", "sql", "python"]

The output keeps the first "ml", first "sql", and then "python".

Already unique
Input[3, 1, 4]
Expected[3, 1, 4]

Nothing is removed because no value repeats.

Hidden Test Categories
Empty listAll values repeatedNumbers mixed with negative valuesValues that would change order if sorted