Open essepuntato opened 4 years ago
my_set = set()
my_set.add("Bilbo")
my_set.add("Frodo")
my_set.add("Sam")
my_set.add("Pippin")
my_set.add("Merry")
my_set.remove("Bilbo")
#my_set is now consisting in {"Frodo", "Pippin", "Sam", "Merry"}
my_set.add("Galadriel")
#my_set is now consisting in {"Frodo", "Pippin", "Sam", "Merry", "Galadriel"}
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
#my_set is now consisting in {"Frodo", "Pippin", "Sam", "Merry", "Galadriel", "Gandalf", "Saruman"}
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set.remove("Bilbo") # it removes "Bilbo"
# my_set became:
# {'Sam', 'Frodo', 'Merry', 'Pippin'}
my_set.add("Galadriel") # It adds "Galadriel" to the set without any particular order
# my_set became:
# {'Sam', 'Frodo', 'Galadriel', 'Merry', 'Pippin'}
my_set.update(set({"Saruman", "Frodo", "Gandalf"})) # It only adds "Saruman" and "Gandalf", because "Frodo" is already included
# my_set became:
# {'Saruman', 'Sam', 'Frodo', 'Galadriel', 'Merry', 'Pippin', 'Gandalf'}
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set.remove("Bilbo")
# this removes the element "Bilbo" from the set
my_set.add("Galadriel")
# this adds the element "Galadriel" to the set
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
# this adds the element "Saruman" and "Gandalf" to the set
Consider the set created in the first exercise, stored in the variable
my_set
. Describe the status of my_set
after the execution of each of the following operations:my_set.remove("Bilbo")
, my_set.add("Galadriel")
,my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
.