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}
Hint:
Use the difference_update() method of a set.
difference_update()
Solution:
set1 = {10, 20, 30} set2 = {20, 40, 50} set1.difference_update(set2) print(set1)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Hint:
Use the
difference_update()
method of a set.Solution:
need an explanation for this answer? contact us directly to get an explanation for this answer