EN
Python - print common elements of two sets
0 points
In this article, we would like to show you how to print common elements of two sets in Python.
In this example, we use intersection_update()
method to keep only the common elements from my_set1
and my_set2
.
xxxxxxxxxx
1
my_set1 = {'A', 'B', 'C'}
2
my_set2 = {'X', 'B', 'C'}
3
4
my_set1.intersection_update(my_set2)
5
6
print(my_set1) # {'B', 'C'}
Output:
xxxxxxxxxx
1
{'B', 'C'}