PY-34

Remove Repeats without Changing Order

  • Easy
  • Sets and Ordering
  • Python

Task

Write unique_in_order(values). It receives a list of hashable values and returns a new list containing the first occurrence of each value, in the order in which those first occurrences appear. A value is repeated when it compares equal to an earlier value. The input list must not change.

Example

The first "red" and first "blue" determine the output positions; later occurrences are skipped. An empty input returns an empty list.

Your implementation

Edit solution.py and keep this function name and signature:

Return a list, and make it a different outer list from values. Preserve the original value objects in their first-seen order. You may rely on every input value being hashable. Do not modify values.