BeginnerCoder

Lesson 6 — Sets: dedupe while keeping order

Sets for fast "have I seen this?"

Checking x in some_list looks at every item — slow for big lists. x in some_set is instant. A common pattern: remove duplicates while keeping the original order, using a set to remember what you have already seen.

seen = set()
seen.add("a")
"a" in seen   # True

(set(list) also removes duplicates, but it loses the order.)

Why it matters: cleaning duplicate emails or IDs from a sign-up list is a daily task, and the seen-set pattern does it in one fast pass.

Want it another way?
Task

Inside the if, add the email to both seen and result. Expected: 3 unique emails in original order.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.