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


The program creates two sets x and y with values {10, 20, 30, 40, 50} and {40, 50, 60, 70, 80} respectively. The union method is then used to find the union of the two sets, i.e., all the elements that are present in either of the sets. The result of the union method is stored in the set z. Finally, the value of z is printed which contains all the elements from both sets, i.e., {10, 20, 30, 40, 50, 60, 70, 80}.

Source Code

x = {10, 20, 30, 40, 50}
y = {40, 50, 60, 70,80}
z = x.union(y)
print(z)

Output

{70, 40, 10, 80, 50, 20, 60, 30}