Python Practice › Set Programs › Program 33
Remove several elements
Write a Python program to remove several elements at once.
Input
{1, 2, 3, 4, 5}, remove [2, 4]Output
{1, 3, 5}Approach
difference_update()or-=.
Solution
s = {1, 2, 3, 4, 5}s -= {2, 4}print(s)Output
{1, 3, 5}Learn the concept
New to this topic? Read the lesson, then come back.