'''
A set in Python is an unordered collection of unique elements. This means that sets cannot contain duplicate values, and the order of elements is not guaranteed. Sets are commonly used for tasks such as membership testing, removing duplicates, and mathematical operations like union, intersection, and difference.
'''
# Books in three cities:
# Akkurgan, Tashkent and Navai
books_Akkurgan = {
"The days gone by",
"The Great Gatsby",
"To Kill a Mockingbird",
"The Da Vinci Code",
"The Hitchhiker's Guide to the Galaxy",
"Harry Potter and the Sorcerer's Stone"}
books_Tashkent = {
"The Great Gatsby",
"To Kill a Mockingbird",
"The Da Vinci Code",
"The Hitchhiker's Guide to the Galaxy",
"Harry Potter and the Sorcerer's Stone",
"To Kill a Mockingbird",
"The Da Vinci Code",
"The Hitchhiker's Guide to the Galaxy",
"The Hitchhiker's Guide to the Galaxy",
"Harry Potter and the Sorcerer's Stone"}
books_Navai = {
"The Hitchhiker's Guide to the Galaxy",
"Harry Potter and the Sorcerer's Stone",
"The Hitchhiker's Guide to the Galaxy",
"Harry Potter and the Sorcerer's Stone"}
# The list of books that are available in all 3 cities
print("The list of books that are available in all 3 cities: ",
books_Akkurgan.intersection(books_Tashkent).intersection(books_Navai))
# The list of books that are available in at least 2 cities
print("The list of books that are available in at least 2 cities",
books_Akkurgan.intersection(books_Tashkent).
union(books_Tashkent.intersection(books_Navai)).
union(books_Navai.intersection(books_Akkurgan)))
# The list of the books in all 3 cities or some
print("The list of the books in all 3 cities or some: ",
books_Akkurgan.union(books_Tashkent).union(books_Navai))
# The list of the books available only in city:
print("The list of the books available only in city: ",
books_Akkurgan.difference(books_Tashkent).
union(books_Tashkent.difference(books_Navai)).
union(books_Navai.difference(books_Akkurgan))
)
# The books that are available only in Akkurgan
print("The books that are available only in Akkurgan: ",
books_Akkurgan.difference(books_Tashkent).
difference(books_Navai)
)
# The books that are available only in Tashkent
print("The books that are available only in Tashkent: ",
books_Tashkent.difference(books_Akkurgan).
difference(books_Navai)
)
# The books that are available only in Navai
print("The books that are available only in Navai: ",
books_Navai.difference(books_Tashkent).
difference(books_Akkurgan)
)
# Add a new book - unique book to the list of Tashkent
books_Tashkent.add("1994")
# The books that are available only in Tashkent
print("The books that are available only in Tashkent: ",
books_Tashkent.difference(books_Akkurgan).
difference(books_Navai)
)
books_Navai.remove("Harry Potter and the Sorcerer's Stone")
print(books_Navai)
books_Navai.remove("Harry Potter and the Sorcerer's Stone")