Python Fundamentals / Collections
Lesson 27 of 38
Sets
A set holds unique values with no order. Great for removing duplicates and checking membership fast.
Key points
- set([1,1,2]) gives {1, 2}
- a & b: in both
- a | b: in either
seen = {"10.0.0.1", "10.0.0.2"}
seen.add("10.0.0.1")
print(len(seen)) # 2Quiz · +10 XP
What does len(set([1, 1, 2, 2, 3])) give?
Log in to save progress and earn XP.