Q:

Write a Python program to return a new set with unique items from both sets by removing duplicates.

belongs to collection: Python Set Exercises

0

Get Only unique items from two sets

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.

All Answers

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

Hint:

Use the union() method of a set.

Solution:

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

print(set1.union(set2))

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

total answers (1)

Given two Python sets, write a Python program to u... >>
<< Return a new set of identical items from two sets ...