Python 3 Code to Find Difference Between Two Sets Using (-) Operator & difference() Method

main1.py

A = {'a', 'b', 'c', 'd'}
B = {'c', 'f', 'g'}

# Equivalent to A-B
print(A.difference(B))

# Equivalent to B-A
print(B.difference(A))

main2.py

A = {'a', 'b', 'c', 'd'}
B = {'c', 'f', 'g'}

print(A-B)

print(B-A)

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.