Q:

Update set1 by adding items from set2, except common items using python programming

belongs to collection: Python Set Exercises

0

Update set1 by adding items from set2, except common items

Given:

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

Expected output:

{70, 10, 20, 60}

All Answers

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

Hint:

Use the symmetric_difference_update() method of a set.

Solution:

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

set1.symmetric_difference_update(set2)
print(set1)

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

total answers (1)

Remove items from set1 that are not common to both... >>
<< Check if two sets have any elements in common. If ...