belongs to collection: Python Set Exercises
Write a Python program to return a new set with unique items from both sets by removing duplicates.
Given:
set1 = {10, 20, 30, 40, 50} set2 = {30, 40, 50, 60, 70}
Expected output:
{70, 40, 10, 50, 20, 60, 30}
Note: set is unordered so not necessary this will be the order of the item.
Hint:
Use the union() method of a set.
union()
Solution:
set1 = {10, 20, 30, 40, 50} set2 = {30, 40, 50, 60, 70} print(set1.union(set2))
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
union()
method of a set.Solution:
need an explanation for this answer? contact us directly to get an explanation for this answer