Python Practice › Set Programs › Program 33

Remove several elements

EasySet Programs · 33 of 48

Write a Python program to remove several elements at once.

Advertisement
Input
{1, 2, 3, 4, 5}, remove [2, 4]
Output
{1, 3, 5}

Approach

  1. difference_update() or -=.

Solution

Python
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.

More set programs

← All 48 Set Programs

Leave a Comment