🧩Set
Also known as Hash Set
A group of values with no repeats. Each value is in it just once.
Think of it like
Think of it like a sticker book. Each sticker goes in once, and a spare has no spot.
Example
A blog has the tags red, blue and red on one post. Put in a set, the tags become just red and blue.
Why it matters
Checking if something is in a set is much faster than searching a long list. It also clears out repeats for free.
Definition
Example code
python
>>> tags = {"red", "blue", "red"}
>>> len(tags)
2
>>> "red" in tags
TrueCommon mistake
Key takeaways
- 1No repeats. Each value is kept only once.
- 2No set order. Items have no first or last.
- 3Fast to check. Is it in here? is answered at once.