ex347.py

# Operations with sets in python
set1 = {-1,0,4,5,6}
set2 = {-5,0,4,7,8}
# Finding the differences between two sets
print(set1.difference(set2))
print(set2.difference(set1))
# Finding the duplicate items in two sets
print(set1.intersection(set2))
# Combining sets
print(set1.union(set2))
print(set2.union(set1))
# Determining whether one set is a superset of another
set1 = {1,2,3,4,5}
set2 = {1,2,3}
print(set1.issuperset(set2))
print(set2.issuperset(set1))
# Output:
#{5, 6, -1}
#{8, -5, 7}
#{0, 4}
#{0, 4, 5, 6, 7, 8, -5, -1}
#{0, 4, 5, 6, 7, 8, -5, -1}
#True
#False

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading