Skip to content
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

Open
essepuntato opened this issue Nov 15, 2023 · 22 comments
Open
Labels

Comments

@essepuntato
Copy link
Contributor

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"})).

@Liber-R
Copy link

Liber-R commented Nov 15, 2023

Screenshot 2023-11-15 102309

@Asemica-me
Copy link

My set = {"Pippin", "Frodo", "Bilbo", "Merry", "Sam"}

my_set = {"Pippin", "Frodo", "Bilbo", "Merry", "Sam"}
my_set.remove("Bilbo")
​my_set.add("Galadriel")
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))

Output:

{"Gandalf", "Merry", "Sam", "Pippin", "Frodo", "Saruman", "Galadriel"}

Current status of my_set :
My set = {"Gandalf", "Merry", "Sam", "Pippin", "Frodo", "Saruman", "Galadriel"}

@valentinabertelli
Copy link

my_set = set({"Bilbo", "Frodo", "Sam", "Pippin", "Merry"})

my_set.remove("Bilbo") #"Bilbo" is removed from the set
#my_set became:
#set({"Frodo", "Pippin", "Sam", "Merry"})

my_set.add("Galadriel") #"Galadriel" is added to the set
#my_set became:
#set = ({"Frodo", "Pippin", "Galadriel", "Sam", "Merry"})

my_set.update(set({"Saruman", "Frodo", "Gandalf"})) #"Saruman" and "Gandalf" are added to the set, "Frodo" is not added to the set because is already present
#my_set became:
#set = ({"Frodo", "Pippin", "Saruman", "Galadriel","Gandalf","Sam","Merry"})

@Alice-Ant
Copy link

my_set.remove("Bilbo") - removes "Bilbo" from the set
{"Frodo", "Pippin", "Sam", "Merry"}

my_set.add("Galadriel") - adds "Galadriel" to the set
{"Frodo", "Pippin", "Galadriel", "Sam", "Merry"}

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
{'Sam', 'Saruman', 'Pippin', 'Merry', 'Frodo', 'Galadriel', 'Gandalf'}

@katyakrsn
Copy link

katyakrsn commented Nov 15, 2023

my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set.remove("Bilbo")  # Bilbo is removed from the set
my_set.add("Galadriel")  # Galadriel is added to the set
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))  # Adds these new elements to my_set, except for Frodo
print(my_set)

@ThIheb
Copy link

ThIheb commented Nov 15, 2023

my_set = {"Bilbo", "Frodo", "Sam", "Pippin, "Merry"}
my_set.remove("Bilbo")
#The string "Bilbo" will be removed from the set

my_set.add("Galdriel")   
#The string "Galdriel is added to the set

my_set.update(set({"Saruman", "Frodo", "Gandalf"}))

#The state of the set will be {"Frodo", "Sam", "Pippin", "Merry", "Galdriel", "Saruman", "Gandalf"}
The string "Frodo" wasn't added because it already existed in the first set

@qwindici
Copy link

qwindici commented Nov 16, 2023

my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
# remove 'Bilbo'
my_set.remove("Bilbo")
# add "Galadriel"
my_set.add("Galadriel")
# add the set {"Saruman", "Frodo", "Gandalf"}, the element already in the set won't be repeated
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))

print(my_set)  # {'Sam', 'Saruman', 'Galadriel', 'Merry', 'Frodo', 'Gandalf', 'Pippin'}

@krzywonos
Copy link

my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set.remove("Bilbo")
# my_set = {"Sam", "Frodo", "Merry", "Pippin"}
my_set.add("Galadriel")
# my_set = {"Frodo", "Sam", "Galadriel", "Pippin", "Merry"}
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
# my_set = {"Frodo","Galadriel", "Sam", "Saruman", "Pippin", "Gandalf", "Merry"}

@MariaFrancesca6
Copy link

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'}

@rufferbaraldi
Copy link

my_set = {'Sam', 'Frodo', 'Pippin', 'Bilbo', 'Merry'}
my_set.remove("Bilbo")
#my_set = {'Frodo', 'Sam', 'Pippin', 'Merry'}

my_set.add("Galadriel")
#my_set = {'Frodo', 'Sam', 'Pippin', 'Galadriel', 'Merry'}

my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
#my_set = {'Sam', 'Galadriel', 'Saruman', 'Merry', 'Gandalf', 'Pippin',  'Frodo'}

@enricabruno
Copy link

# 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'}

@frammenti
Copy link

my_set = {"Saruman", "Gandalf", "Merry", "Sam", "Frodo", "Galadriel", "Pippin"}

@alicepiazzi
Copy link

my_first_set = set()  # create an empy set
my_first_set.add ("Bilbo") # add elements
my_first_set.add ("Frodo")
my_first_set.add ("Sam")
my_first_set.add ("Pippin")
my_first_set.add ("Merry")
my_first_set.remove("Bilbo") # remove elements
my_first_set.add("Galadriel") # add an element
my_first_set.update(set({"Saruman", "Frodo", "Gandalf"})) #current status of my_first_set

print (my_first_set)

my_first_set = {"Galadriel", "Saruman", "Gandalf", "Pippin", "Sam", "Frodo", "Merry"}``

@saramadonia
Copy link

my_set = {"Sam", "Pippin", "Merry", "Frodo", "Bilbo"}

my_set.remove("Bilbo") # removes "Bilbo" element to the set
print(my_set)
Sam Pippin Merry Frodo

​my_set.add("Galadriel") # adds "Galadriel" element to the set
print(my_set)
Sam Pippin Galadriel Merry Frodo

​my_set.update(set({"Saruman", "Frodo", "Gandalf"})) # adds to my_set elements from another set
print(my_set)
Sam Pippin Galadriel Frodo Merry Saruman Gandalf

@Sergpoipoip
Copy link

after the execution of the provided operations with my_set this variable will store the set {'Saruman', 'Merry', 'Frodo', 'Sam', 'Gandalf', 'Pippin', 'Galadriel'}

@simocasaz
Copy link

a_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set.remove("Bilbo") # The item "Bilbo" is no longer in the set
​my_set.add("Galadriel") # The item "Galadriel" has been added to the set
​my_set.update(set({"Saruman", "Frodo", "Gandalf"})) # The items "Saruman" and "Gandalf" are now in the set. The item "Frodo" has not been added, since it was already present in my_set

@Chiaramartina
Copy link

my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set.remove("Bilbo")
#Bilbo has been removed
my_set.add("Galadriel")
#Galadriel has been added
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
#The set was updated with new elements but "Frodo" wasn't repeated
print (my_set)

my_set={'Frodo', 'Sam', 'Merry', 'Saruman', 'Galadriel', 'Pippin', 'Gandalf'}

@matildepassafaro
Copy link

my_set = {"Sam", "Pippin", "Bilbo", "Frodo", "Merry"}

status of my_set after the execution of my_set.remove("Bilbo"):
my_set = {"Sam", "Pippin", "Frodo", "Merry"}

status of my_set after the execution of my_set.add("Galadriel"):
my_set = {"Sam", "Pippin", "Galadriel", "Frodo", "Merry"}

status of my_set after the execution of my_set.update(set({"Saruman", "Frodo", "Gandalf"})):
my_set = {"Sam", "Gandalf", "Pippin", "Saruman", "Galadriel", "Frodo", "Merry"}

@CarlaMenegat
Copy link

Captura de Tela 2023-11-19 às 20 00 47

@VirginiaDa00
Copy link

es2 lez 7

@essepuntato
Copy link
Contributor Author

Thanks for your takes. Just one comment:

@annapasetto0
Copy link

annapasetto0 commented Nov 27, 2023

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") #Bilbo is removed (Frodo, Sam, Pippin, Merry)
my_set.add("Galadriel") #Galadriel is added to the set (Frodo, Sam, Pippin, Merry, Galadriel)
my_set.update(set({"Saruman", "Frodo", "Gandalf"})) #Saruman and Gandalf are now in my_set

print(my_set)

#output: {'Saruman', 'Frodo', 'Galadriel', 'Gandalf', 'Merry', 'Sam', 'Pippin'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests