Sets
Like this video? Get new free AI lessons on YouTube.
SubscribeA set is an unordered collection of unique values. Sets shine at two things: removing duplicates and answering "is this in here?" very fast. They also support classic math operations like union and intersection.
What You'll Learn
- Creating sets and removing duplicates
- Adding and removing elements
- Membership testing
- Union, intersection, and difference
Creating Sets
Sets use curly braces, but unlike dictionaries they hold single values, not pairs. Duplicates disappear automatically:
Adding and Removing
Membership Testing
Checking in on a set is very fast, even for huge collections. This is the main reason to reach for a set:
Set Math
A Practical Example
Key Takeaways
- Sets hold unique values with no order:
{1, 2, 3} set(list)removes duplicates instantlyadd()anddiscard()change a setinon a set is very fast|union,&intersection,-difference
Quiz
Up next · Lesson 21 of 24
Project: Contact Book
1 min read
20 of 24 lessons done

Ask Byte about this lesson
A private chat about this lesson. Byte has read the whole lesson, answers in seconds, and shows the section each answer comes from. Ask follow-ups in any language.
Questions & Answers
Public questions about this lesson. The AI Tutor answers right away in your language, the FreeAcademy team checks answers, and every learner can read them.

