-
Notifications
You must be signed in to change notification settings - Fork 0
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 = {"Pippin", "Frodo", "Bilbo", "Merry", "Sam"}
Output:
Current status of |
|
my_set.remove("Bilbo") - removes "Bilbo" from the set my_set.add("Galadriel") - adds "Galadriel" to the set my_set.update(set({"Saruman", "Frodo", "Gandalf"})) - adds "Saruman" and "Gandalf" to the set, "Frodo" is not added, already present Current status of my_set is |
|
|
|
|
my_set = {'Bilbo', 'Frodo', 'Merry', 'Pippin', 'Sam'}
my_set.remove("Bilbo")
#the "Bilbo" string has been removed
print(my_set)
my_set = {'Frodo', 'Sam', 'Pippin', 'Merry'}
my_set.add("Galadriel")
#the "Galadriel" string has been added
print(my_set)
my_set = {'Galadriel', 'Frodo', 'Sam', 'Pippin', 'Merry'}
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
#the method update add elements from another set
print(my_set)
my_set = {'Galadriel', 'Frodo', 'Saruman', 'Sam', 'Pippin', 'Gandalf', 'Merry'} |
|
# creation of the set with the given elements
my_set = set({"Bilbo", "Frodo", "Sam", "Pippin", "Mery"})
# the current set
print(my_set)
# removing the element "Bilbo"
my_set.remove("Bilbo")
# first status of the set without "Bilbo"
print(my_set)
# addition of the element "Galadriel"
my_set.add("Galadriel")
# second status of the set with the addition of "Galadriel"
print(my_set)
# updating the set with new given elements
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
# third status of the set updated
print(my_set) final output: {'Sam', 'Mery', 'Pippin', 'Saruman', 'Galadriel', 'Gandalf', 'Frodo'} |
my_set = {"Saruman", "Gandalf", "Merry", "Sam", "Frodo", "Galadriel", "Pippin"} |
|
my_set = {"Sam", "Pippin", "Merry", "Frodo", "Bilbo"} my_set.remove("Bilbo") # removes "Bilbo" element to the set my_set.add("Galadriel") # adds "Galadriel" element to the set my_set.update(set({"Saruman", "Frodo", "Gandalf"})) # adds to my_set elements from another set |
after the execution of the provided operations with |
|
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"} my_set={'Frodo', 'Sam', 'Merry', 'Saruman', 'Galadriel', 'Pippin', 'Gandalf'} |
my_set = {"Sam", "Pippin", "Bilbo", "Frodo", "Merry"} status of my_set after the execution of my_set.remove("Bilbo"): status of my_set after the execution of my_set.add("Galadriel"): status of my_set after the execution of my_set.update(set({"Saruman", "Frodo", "Gandalf"})): |
Thanks for your takes. Just one comment:
|
my_set = set() my_set.remove("Bilbo") #Bilbo is removed (Frodo, Sam, Pippin, Merry) print(my_set) #output: {'Saruman', 'Frodo', 'Galadriel', 'Gandalf', 'Merry', 'Sam', 'Pippin'} |
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: