Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Create and use a set

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

Python practice6 minDictionaries & SetsBeginnerLast updated March 18, 2026

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]

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 1

Input

[3, 1, 2, 3]

Output

[1, 2, 3]

Duplicates removed, then sorted.