Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 10

Convert a list to a set to remove duplicates

Easy

8 minute session

Summary

Learn how to remove duplicate items from a list by converting it to a set and returning a canonical sorted result.

Problem statement

Given a list of hashable and comparable items, remove any duplicates by converting the list to a set, then return the unique items as a sorted list. This provides a canonical ordering for testing and predictable output.

Task

Write a function that removes duplicates from a list by using a set and returns a sorted list of the unique items.

Examples

Remove duplicates from integers

Input

list_to_set([3, 1, 2, 3])

Output

[1, 2, 3]

Explanation

Convert to a set to drop the duplicate 3, then sort to get a consistent list [1, 2, 3].

Input format

A single list of hashable, comparable items (numbers or strings).

Output format

A sorted list containing each unique item from the input exactly once.

Constraints

Elements in the list are hashable and mutually comparable (so sorting works). List length can be large (e.g., up to 100000), so aim for reasonable time/space usage.

Samples

Sample input 0

[1, 1, 2, 2, 3]

Sample output 0

[1, 2, 3]

Explanation 0

Duplicates removed and result sorted.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

09:10 PM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.