Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 7

Create and use a set

Easy

6 minute session

Summary

Learn how to create a set from a collection to get unique items and return them in a deterministic order.

Problem statement

Given a collection (list) of comparable, hashable items, create a set of unique items and return the unique items as a sorted list. Use Python's set type to remove duplicates. Sorting the result makes the output deterministic for testing and presentation.

Task

Convert a list-like collection into a set to remove duplicates, then return the unique items sorted.

Examples

Remove duplicates from a list of integers

Input

[3, 1, 2, 3]

Output

[1, 2, 3]

Explanation

Convert the list to a set to get {1,2,3} then return it as a sorted list [1,2,3].

Input format

A single list of comparable, hashable items (e.g., integers or strings).

Output format

A sorted list containing the unique items from the input.

Constraints

All items in the input list are hashable and of a type that can be compared with sorted (e.g., all ints or all strings).

Samples

Sample input 0

[3, 1, 2, 3]

Sample output 0

[1, 2, 3]

Explanation 0

Duplicates removed, then 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.

07:40 PM

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