Python Practice › Set Programs › Program 38
Difference with several sets
Write a Python program to remove from one set the items of several others.
Input
{1, 2, 3, 4, 5}, {2}, {4, 5}Output
{1, 3}Approach
difference()accepts several sets.
Solution
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.