Skip to content
IT Vizag
← Lists, Dicts & Data

▶ 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

Lesson 4 of 9 · 1 min read

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.

🔒 Code example: sign up free (above) to unlock it.

An empty set is written set(), because {} makes an empty dictionary.

Removing duplicates from a list

The most common use, in one line:

🔒 Code example: sign up free (above) to unlock it.

The order isn't kept. If order matters, use list(dict.fromkeys(emails)) instead.

Adding and checking

🔒 Code example: sign up free (above) to unlock it.

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

🔒 Code example: sign up free (above) to unlock it.

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.

Tip: Sets can only hold unchangeable values like numbers, strings and tuples. A list inside a set gives a TypeError.

In one line

A set keeps only unique values, checks membership very fast, and answers "both / either / only" questions with &, | and -.

Saved on this device. Sign in to keep progress everywhere.

Share with a friend