-
Notifications
You must be signed in to change notification settings - Fork 8
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 #21
Comments
my_set.remove("Bilbo") #remove bilbo from the set |
Considering our starting hobbits({"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}):
We execute:
The final set is: |
#exercise2 starts
|
set_tolkien= () Current status of set_tolkien: ({"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}) set_tolkien.remove("Bilbo") Current status of set_tolkien: ({"Frodo", "Sam", "Pippin", "Merry"}) set_tolkien.add("Galadriel") Current status of set_tolkien: ({"Frodo", "Sam", "Pippin", "Merry", "Galadriel"}) set_tolkien.update({"Saruman", "Frodo", "Gandalf"})) Current status of set_tolkien: ({"Frodo", "Sam", "Pippin", "Merry", "Galadriel", "Saruman", "Gandalf"}) |
initial stage of the set protagonists= ({"Bilbo", "Frodo", "Sam", "Pippin", "Merry"})protagonists.remove("Bilbo")- will remove "Bilbo" current status of the set - ({"Frodo", "Sam", "Pippin", "Merry"})protagonists.add("Galadriel")- will add "Galadriel" current status of the set -({"Frodo", "Sam", "Galadriel", "Pippin", "Merry"})protagonists.update(set({["Saruman", "Frodo", "Gandalf"})) -will add all except "Frodo", as the set doesn't accept repeatability of items final status of the set ({"Frodo", "Saruman", "Sam", "Gandalf", "Galadriel", "Pippin", "Merry"}) |
mag_set = set() my_set = set() #my_set({"Pippin", "Gandalf", "Sam", "Merry", "Frodo", "Saruman", "Galadriel"}) |
|
|
my_name_set = set() |
|
#Theoden: so, it begins sauron._set({"Bilbo", "Frodo", "Pippin", "Sam", "Merry"}) Actions: #first step: #second step #third step #end, now go to defend Helm's Deep. |
In the second line, "Bilbo" dies on set. The set now persists of {'Frodo', 'Sam', ‘Merry', ‘Pippin'}. |
mordor_set = set() #used set() to create a new set print(mordor_set) #{'Frodo', 'Pippin', 'Merry', 'Bilbo', 'Sam'} mordor_set.remove("Bilbo") #method remove used to remove string "Bilbo" print(mordor_set) #{'Gandalf', 'Frodo', 'Pippin', 'Merry', 'Galadriel', 'Saruman', 'Sam'} |
hobbitset=set (["Frodo","Bilbo","Sam","Pippin","Merry"]) |
set(['Bilbo', 'Merry', 'Pippin', 'Sam', 'Frodo']) output set(['Pippin', 'Galadriel', 'Sam', 'Frodo', 'Merry', 'Gandalf', 'Saruman']) |
my_set.remove("Bilbo"), my_set.add("Galadriel"), my_set.update(set({"Saruman", "Frodo", "Gandalf"})) my_set{'Bilbo', 'Merry', 'Pippin', 'Sam', 'Frodo'} Output: my_set{'Merry', 'Pippin', 'Sam', 'Frodo', 'Galadriel', 'Saruman', 'Gandalf'} |
my_set=({"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}) my_set.remove("Bilbo") my_set.add("Galadriel") my_set.update(set({"Saruman", "Frodo", "Gandalf"})) |
Considering the first exercise: the_hobbits = set() exercise 2: my_set.remove("Bilbo"), my_set.add("Galadriel"), my_set.update(set({"Saruman", "Frodo", "Gandalf"})). the_hobbits.remove("Bilbo") # this removes "Bilbo" from the set the_hobbits.add("Galadriel") # this adds "Galadriel" to the set the_hobbits.update(set({"Saruman", "Frodo", "Gandalf"})) print(the_hobbits) Output: set({'Galadriel', 'Gandalf', 'Pippin', 'Frodo', 'Sam', 'Saruman', 'Merry'}) |
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: