Skip to content
Exercise · Dicts and sets · lesson 11 of 11

Exercise: no duplicates

Write a function unique(items) that returns a new list of the elements of the list items without repeats. Each element occurs in the result once, in the order in which the elements first appear in items.

  • unique([3, 1, 3, 2, 1]) → [3, 1, 2]
  • unique(["b", "a", "b"]) → ["b", "a"]
  • unique([]) → []

Constraints: the elements are numbers or strings; an empty list gives an empty list; the function does not change the list items itself.

Do not add extra imports unless the task says so explicitly.

unique.py — python
python · 3 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way