Lesson guide
What this Python exercise practices
Create and use a set is a beginner practice lesson that focuses on lists, iteration, filtering. It is designed to be solved in about 6 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- List values
- Basic indexing
Difficulty and time
- Level
- Beginner
- Estimated time
- 6 minutes
Practice path
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.
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.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.