Python Practice › Set Programs › Program 38

Difference with several sets

EasySet Programs · 38 of 48

Write a Python program to remove from one set the items of several others.

Advertisement
Input
{1, 2, 3, 4, 5}, {2}, {4, 5}
Output
{1, 3}

Approach

  1. difference() accepts several sets.

Solution

Python
print({1, 2, 3, 4, 5}.difference({2}, {4, 5}))
Output
{1, 3}

Learn the concept

New to this topic? Read the lesson, then come back.

More set programs

← All 48 Set Programs

Leave a Comment