Python Set Subset || Remove Intersection || Sets || Python
In this we are going to see a basic program to remove elements which are intersecting from first set in Python Programming Language.


set1 = {4, 5, 8, 1, 2}
set2 = {3, 8, 9, 1, 7}
print("Set1 : ", set1)
print("Set2 : ", set2)

# For Removing The Elements Which Are Intersecting From 1st Set
# First Method
set2.difference_update(set1)
print("After Removing The Elements Which Are Intersecting From 1st Set, The Sets Are(Using Difference Update)")
print("-------------------------------------")
print("Set1 : ", set1)
print("Set2 : ", set2)

# Second Method
set2 -= set1
print("After Removing The Elements Which Are Intersecting From 1st Set, The Sets Are(Using - Operator)")
print("-------------------------------------")
print("Set1 : ", set1)
print("Set2 : ", set2)

# Coded By DHIRAJ SHELKE


#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post