Python Practice › Set Programs › Program 25
difference() vs –
Write a Python program to find the difference between two sets with the method and the operator.
Input
{"a", "b", "c"}, {"b"}Output
['a', 'c'] ['a', 'c']
Approach
difference()accepts any iterable;-needs sets.
Solution
a = {"a", "b", "c"}print(sorted(a.difference(["b"])), sorted(a - {"b"}))Output
['a', 'c'] ['a', 'c']
Learn the concept
New to this topic? Read the lesson, then come back.