Python Practice › Set Programs › Program 8
Difference of two sets
Write a Python program to find the items in the first set but not the second.
Input
{1, 2, 3, 4}, {3, 4, 5}Output
{1, 2} {5}Approach
-ordifference(); the order of the sets matters.
Solution
a, b = {1, 2, 3, 4}, {3, 4, 5}print(a - b, b - a)Output
{1, 2} {5}Learn the concept
New to this topic? Read the lesson, then come back.