Sets in Python — a practical guide to Python sets with clear examples you can reuse in real projects.
Python Tutorial Series (23/95). Prefer one article? Read the complete Python tutorial.
Short description
Sets automatically remove duplicates and are fast for membership tests.
Set operations
a = {1, 2, 2, 3}
b = {3, 4}
print(a) # {1, 2, 3}
print(a | b) # union
print(a & b) # intersection
print(2 in a)