Python Practice › Set Programs › Program 9

Symmetric difference

EasySet Programs · 9 of 48

Write a Python program to find the items in exactly one of two sets.

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

Approach

  1. ^ or symmetric_difference().

Solution

Python
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.

More set programs

← All 48 Set Programs

Leave a Comment