Unordered and unique
Unlike a list, a set does not care about order and never stores duplicates. Asking “is x in the set?” is the core question — membership.
In Python, set is built on a hash table (same family as dict). That is why membership and insert are typically fast.
s = set() s.add(3) s.add(8) s.add(3) # ignored — already there 8 in s # True s.discard(3)
Chips float in a bag — order on screen is not meaningful.
Run the simulation
Switch modes: basics, set algebra, and subset relationships.
Build a set
Add, remove, or check membership. Duplicates are ignored.
Set mental model
Unique elements, membership first, then algebra.
No duplicates
Adding an existing element leaves the set unchanged.
Union · ∩ · Difference
| / & / - in Python build new sets from two inputs.
Hash table under the hood
Python set / Java HashSet store elements by hash — see the hash table sim next.