Professional Documents
Culture Documents
PB2
PB2
print(myset)
print(myset1.intersection(myset2))
print(myset1.union (myset2))
4.Update the first set with elements that don’t exist in second set
Myset1 = {1, 2, 3, 4, 5}
Myset2 = {4, 5, 6, 7, 8}
Myset1.update(myset2 -myset1)
Print(myset1)
myset1 = {1, 2, 3, 4, 5}
items_to_remove = {4, 5}
myset1.difference_update(items_to_remove)
print(myset1)
B = {4, 5, 6, 7, 8}
print(A.union(B))
myset1 = {1, 2, 3, 4, 5}
myset2 = {9, 8, 7, 6, 5}
myset3 = myset1.intersection(myset2)
if (myset1.intersection(myset2)) != {}:
print(“Common items:”,myset3)
myset1 = {1, 2, 3, 4, 5, 6}
myset2 = {6, 7, 8, 9, 0, 1}
myset1.update(myset2)
print(myset1)
9.Remove items from set1 that are not common in both set1 and set2
myset1 = {1, 2, 3, 4, 5, 6}
myset2 = {6, 7, 8, 9, 0, 1}
myset2.difference(myset1)
print(myset2)