Python Practice › Set Programs › Program 26
Update a set to its intersection
Write a Python program to keep only the items shared with another set.
Input
{1, 2, 3, 4}, {2, 4, 6}Output
{2, 4}Approach
intersection_update()or&=.
Solution
a = {1, 2, 3, 4}a &= {2, 4, 6}print(a)Output
{2, 4}Learn the concept
New to this topic? Read the lesson, then come back.