Q:

Return a set of elements present in Set A or B, but not both using python programming

belongs to collection: Python Set Exercises

0

Return a set of elements present in Set A or B, but not both

Given:

set1 = {10, 20, 30, 40, 50}
set2 = {30, 40, 50, 60, 70}

Expected output:

{20, 70, 10, 60}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

Use the symmetric_difference() method of a set.

Solution:

set1 = {10, 20, 30, 40, 50}
set2 = {30, 40, 50, 60, 70}

print(set1.symmetric_difference(set2))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Check if two sets have any elements in common. If ... >>
<< Write a Python program to remove items 10, 20, 30 ...