Q:

Given two Python sets, write a Python program to update the first set with items that exist only in the first set and not in the second set.

belongs to collection: Python Set Exercises

0

Update the first set with items that don’t exist in the second set

Given two Python sets, write a Python program to update the first set with items that exist only in the first set and not in the second set.

Given:

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

Expected output:

set1 {10, 30}

All Answers

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

Hint:

Use the difference_update() method of a set.

Solution:

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

set1.difference_update(set2)
print(set1)

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

total answers (1)

Write a Python program to remove items 10, 20, 30 ... >>
<< Write a Python program to return a new set with un...