
Python set intersection
You can get the intersection of sets by intersection()
in Python.
a = {1, 2, 3}
b = {1, 2, 5}
c = a.intersection(b)
print(c) # {1, 2}
If the intersection is empty, it returns an empty set (set()).
a = {1, 2, 3}
b = {4, 5}
c = a.intersection(b)
print(c) # set()
Intersection operator
a = {1, 2, 3, 4}
b = {1, 2, 6}
c = {1, 2, 7}
d = a & b & c
print(d) # {1, 2}
&
is an intersection operator and it's used to get the intersection of three or more than three sets.
Comments
Powered by Markdown