intersection of two sets in python code example
Example 1: python check if two sets intersect
a = [1, 2, 3]
b = [3, 4, 5]
bool(set(a) & set(b))
Example 2: intersection between two sets python
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.intersection(y)
print(z)
# Output: {"apple"}
Example 3: python set intersection
both = {'a', 'A', 'b', 'B'}
some = {'a', 'b', 'c'}
result1 = both & some
# result: {'a', 'b'}
result2 = both.intersection(some)
print(result1 == result2)
# True