Python Practice › Set Programs › Program 9
Symmetric difference
Write a Python program to find the items in exactly one of two sets.
Input
{1, 2, 3, 4}, {3, 4, 5}Output
{1, 2, 5}Approach
^orsymmetric_difference().
Solution
a, b = {1, 2, 3, 4}, {3, 4, 5}print(a ^ b)Output
{1, 2, 5}Learn the concept
New to this topic? Read the lesson, then come back.