How can I handle the different operations between sets in python Union, Intersection, Difference, Symmetric Difference, Complement, Cartesian Product
A = {1, 2, 3, 4}
B = {1, 3, 6, 7}
A ∪ B
A ∩ B
A \ B
...
...
A × B
How can I handle the different operations between sets in python Union, Intersection, Difference, Symmetric Difference, Complement, Cartesian Product
A = {1, 2, 3, 4}
B = {1, 3, 6, 7}
A ∪ B
A ∩ B
A \ B
...
...
A × B
Create instances of a set.
What objects are accepted in a set? Only objects that are accepted in a function are accepted
hash(..)
On the other hand, tuples
tuple
are accepted in sets in python.How to know if an object is in the set?
and therefore to know if an object is in the set is done with the operator
in
.Operations between Sets
Union
interception
Difference
Symmetric Difference
superset
Subset
Disjoint Sets
Operations with individual elements
Check if an element is in a set
Add items to a set
Add elements to a set:
Remove elements from a set:
Reference: Medium - Everything you need to know about sets in Python — set(…) By LuisMBaezCo