Remove Duplicates from a List
Beginner · Write the code · from Python Sets: Unique Collections, Operations, and Use Cases
From the lesson: Python Sets: Unique Collections, Operations, and Use Cases
Imagine you're a teacher taking attendance. A student accidentally signs the attendance sheet twice. Does that mean they're in class twice? Of course not. You only care about who showed up, not how many times they wrote their name.
Read the lessonYou have a list of email addresses where some appear more than once. Create a set called unique_emails from the emails list and print it sorted alphabetically using sorted().
emails = ['alice@mail.com', 'bob@mail.com', 'alice@mail.com', 'charlie@mail.com', 'bob@mail.com']
# Create a set of unique emails and print them sorted
More Sets exercises
- Predict the Set OutputBeginner
- Find Students in Both ClassesIntermediate
- Fix the Empty Set BugIntermediate
- Find Missing IngredientsIntermediate
- Deduplicate While Preserving OrderAdvanced
All Python exercises · 50 practice problems · Data Structures quiz