Sets
A set keeps unique items and answers fast membership questions. {} is an empty dict; the empty set is set().
Syntax
parts = {"a", "b"}set(recipe) <= set(have)
- | is union, & is intersection, - is difference.
Example
needed = {"wrench", "cable"}
have = {"wrench", "cable", "chip"}
print(needed <= have)Output:
True
Common mistakes
- {} is a dictionary, not a set. Call set() when you need no items yet.