-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Organising information: unordered structures", exercise 2 #22
Comments
|
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"} my_set.remove("Bilbo") my_set.add("Galadriel") my_set.update(set({"Saruman", "Frodo", "Gandalf"})) print(my_set) |
my_set= {"Bilbo","Frodo","Sam","Pippin","Merry"}
my_set.remove("Bilbo")
# "Bilbo" was removed from the set.
#{"Frodo","Sam","Pippin","Merry"}
my_set.add("Galadriel")
# "Galadriel" was added to the set.
#{"Frodo","Sam","Pippin","Merry","Galadriel"}
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
# "Saruman", "Frodo" and "Gandalf" were added from a new set to original set.
#{'Pippin', 'Gandalf', 'Galadriel', 'Merry', 'Frodo', 'Sam', 'Saruman'} |
|
|
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set.remove("Bilbo")
#"Bilbo" is removed from the set
# terminal: {"Sam", "Merry", "Pippin", "Frodo"}
my_set.add("Galadriel")
#"Galadriel" is added to the set
# terminal: {"Galadriel", "Sam", "Pippin", "Frodo", "Merry"}
my_set.update(set(("Saruman", "Frodo", "Gandalf")))
#adding elements included in another set
print(my_set)
#terminal: {'Merry', 'Gandalf', 'Frodo', 'Galadriel', 'Saruman', 'Sam', 'Pippin'} |
elements = set() output: {'Frodo', 'Saruman', 'Pippin', 'Galadriel', 'Merry', 'Sam', 'Gandalf'} |
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set.remove ("Bilbo")
print(my_set)
#Console output
{"Frodo", "Sam", "Pippin", "Merry"}
#"Bilbo" was removed from my_set
my_set.add("Galandriel")
print(my_set)
#Console output
{"Frodo", "Sam", "Pippin", "Merry", "Galandriel"}
#"Galandriel" was added to my_set
my_set.update({"Saruman", "Frodo", "Gandalf"})
print(my_set)
#Console output
{"Frodo", "Sam", "Merry", "Pippin", "Galandriel", "Saruman", "Gandalf"}
#"Saruman" and "Gandalf" were added to my_set, "Frodo" was not added a second time
#In general, elements are returned in a different order every time |
my_set = set(("Bilbo","Frodo","Sam","Merry","Pippin"))
my_set.remove("Bilbo")
# {'Pippin', 'Frodo', 'Sam', 'Merry'}
my_set.add("Galadriel")
#{'Pippin', 'Frodo', 'Sam', 'Galadriel', 'Merry'}
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
#{'Pippin', 'Gandalf', 'Frodo', 'Sam', 'Galadriel', 'Saruman', 'Merry'} |
|
|
#{'Pippin', 'Sam', 'Merry', 'Gandalf', 'Galadriel', 'Frodo', 'Saruman'} |
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set.remove("Bilbo")
# the item "Bilbo" has been removed
my_set.add("Galadriel")
# the item "Galadriel" has been added
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
# of the elements of the new set, only "Saruman" and "Gandalf" have been added to the current set, since "Frodo" was already present
print(my_set)
# Now the set contains:
# set({"Frodo", "Sam", "Pippin", "Galadriel", "Gandalf", "Merry", "Saruman"}) |
my_set = set() my_set.add("Bilbo") my_set.remove("Bilbo") my_set.add("Galadriel") my_set.update(set({"Saruman", "Frodo", "Gandalf"})) #checking {'Saruman', 'Galadriel', 'Pippin', 'Merry', 'Frodo', 'Gandalf'} |
|
Consider the set created in the first exercise, stored in the variable
my_set
. Describe the status ofmy_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"}))
.The text was updated successfully, but these errors were encountered: