▶ Sign up free for the video, slides & prompts
The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.
Checking…
Sets
Unique values and fast membership checks.
🎬 Video version coming soon — read it now
A set is a collection of unique values with no fixed order. Duplicates disappear automatically.
An empty set is written set(), because {} makes an empty dictionary.
Removing duplicates from a list
The most common use, in one line:
The order isn't kept. If order matters, use list(dict.fromkeys(emails)) instead.
Adding and checking
Checking in on a set is very fast, even with millions of items, because sets don't search one by one. That matters when your data gets big.
Set maths
These answer real questions quickly: which customers bought both products, which students missed a class, which skills a job needs that you don't have yet.
In one line
A set keeps only unique values, checks membership very fast, and answers "both / either / only" questions with &, | and -.
Share with a friend