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 #21

Open
essepuntato opened this issue Nov 28, 2018 · 19 comments
Open
Labels
Exercise The exercises that are introduced in the lectures.

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

@essepuntato essepuntato added the Exercise The exercises that are introduced in the lectures. label Nov 28, 2018
@hizclick
Copy link

my_set.remove("Bilbo") #remove bilbo from the set
my_set.add("Galadriel") #adds Galadriel to the set
​my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
#updates my_set by adding "Saruman" and "Gandalf"

@friendlynihilist
Copy link

friendlynihilist commented Nov 28, 2018

Considering our starting hobbits({"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}):

hobbits = set()
hobbits.add("Bilbo")
hobbits.add("Frodo")
hobbits.add("Sam")
hobbits.add("Pippin")
hobbits.add("Merry")

We execute:

hobbits.remove("Bilbo") #"Bilbo" element is removed. our set contains now ({"Frodo", "Sam", "Pippin", "Merry"})
hobbits.add("Galadriel") #"Galadriel" element is added to our "hobbits" set
hobbits.update(lotr({"Saruman", "Frodo", "Gandalf"})) #it updates the first list with the elements contained in the second set. elements in set are not repeatable, so "Frodo" will not be added.

The final set is:
hobbits({"Frodo", "Sam", "Pippin", "Merry", "Galadriel", "Saruman", "Gandalf"})

@andreamust
Copy link

andreamust commented Nov 28, 2018

my_set = set() # this creates a new set
my_set.add("Bilbo") # these 5 lines add five names
my_set.add("Frodo")
my_set.add("Sam")


my_set.add("Pippin")
my_set.add("Merry")
print(my_set)     # the output is {'Bilbo', 'Frodo', 'Pippin', 'Merry', 'Sam'}

#exercise2 starts

my_set.remove("Bilbo")   # this deletes an element
print(my_set)   # the result is {'Sam', 'Merry', 'Pippin', 'Frodo'}

my_set.add("Galadriel")   # this adds a new element
print(my_set)    # the result is {'Sam', 'Merry', 'Galadriel', 'Pippin', 'Frodo'}

my_set.update(set({"Saruman", "Frodo", "Gandalf"}))  # this adds "Saruman" and "Gandalf" but not "Frodo" because this element is already in the list

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

@dersuchendee
Copy link

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

set_tolkien= ()
set_tolkien.add("Bilbo")
set_tolkien.add("Frodo")
set_tolkien.add("Sam")
set_tolkien.add("Pippin")
set_tolkien.add("Merry")

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

@bluebell94
Copy link

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

@beccadelbens
Copy link

mag_set = set()
mag_set.add("Saruman")
mag_set.add("Frodo")
mag_set.add("Gandalf")

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.add("Galadriel")
my_set.update(mag_set)

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

@EleonoraPeruch
Copy link

# this is only one possible combination
# set({"Bilbo", "Merry", "Sam","Frodo","Pippin"}) 

my_set.remove("Bilbo") # the element "Bilbo" will be removed from the set
my_set.add("Galadriel") # add the element "Galadriel" to the set
my_set.update(set({"Saruman", "Frodo", "Gandalf"})) # "Frodo" will not be added 
                                                    # as it is already included in the set

print(my_set)

# set({"Gandalf", "Merry", "Sam", "Galadriel", "Saruman", "Frodo", "Pippin"})
# the elements can be combined in a different order

@simayguzel
Copy link

# I already have the set that I have done in the first exercise which is {'Sam', 'Bilbo', 'Frodo', 'Merry', 'Pippin'} 
hobbitset.remove("Bilbo")
hobbitset.add("Galadriel")
hobbitset.update(set({"Saruman","Frodo","Gandalf"})) #since there is no need to sort the list, we don't have to do an extra execution.
print(hobbitset)

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

@leticiasandra
Copy link

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

@delfimpandiani
Copy link

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({ "Bilbo", "Frodo", "Sam", "Pippin", "Merry" })


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

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

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

@MattiaSpadoni
Copy link

#Theoden: so, it begins

sauron._set({"Bilbo", "Frodo", "Pippin", "Sam", "Merry"})

Actions:
my_set.remove("Bilbo"), ​my_set.add("Galadriel"), ​my_set.update(set({"Saruman", "Frodo", "Gandalf"}))

#first step:
sauron_set.remove("Bilbo")
sauron._set({"Frodo", "Pippin", "Sam", "Merry"})

#second step
​sauron_set.add("Galadriel")
sauron._set({"Frodo", "Pippin", "Sam", "Merry", "Galadriel"})

#third step
sauron_set.update(set({"Saruman", "Frodo", "Gandalf"}))
sauron._set({"Frodo", "Pippin", "Sam", "Merry", "Galadriel", "Saruman", "Frodo", "Gandalf"})

#end, now go to defend Helm's Deep.

@SeverinJB
Copy link

1 set_der_besten_hobbits = set(["Bilbo","Frodo","Sam","Pippin","Merry"])
2 set_der_besten_hobbits.remove("Bilbo”)
3 set_der_besten_hobbits.add("Galadriel")
4 set_der_besten_hobbits.update(set({"Saruman", "Frodo", "Gandalf"}))

In the second line, "Bilbo" dies on set. The set now persists of {'Frodo', 'Sam', ‘Merry', ‘Pippin'}.
In the third line, “Galadriel" fills the gap which "Bilbo" left behind. She is now the first woman on set: {'Frodo', 'Sam', 'Merry', 'Galadriel', ‘Pippin'}.
In the fourth line, two old men and a Frodo double join the set. Seven different characters are now on set: {‘Saruman’, 'Sam', 'Frodo', 'Merry', 'Galadriel', 'Pippin', 'Gandalf'}.

@ilsamoano
Copy link

mordor_set = set() #used set() to create a new set
mordor_set.add("Bilbo") #added new element to the set
mordor_set.add("Frodo") #added new element to the set
mordor_set.add("Sam") #added new element to the set
mordor_set.add("Pippin") #added new element to the set
mordor_set.add("Merry") #added new element to the set

print(mordor_set)

#{'Frodo', 'Pippin', 'Merry', 'Bilbo', 'Sam'}

mordor_set.remove("Bilbo") #method remove used to remove string "Bilbo"
mordor_set.add("Galadriel") #method add used to add string "Galadriel"
mordor_set.update(set({"Saruman", "Frodo", "Gandalf"})) #method update used to add to mordor_set new elements from a second set

print(mordor_set)

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

@Totaro1996
Copy link

hobbitset=set (["Frodo","Bilbo","Sam","Pippin","Merry"])
hobbitset.remove("Bilbo") #it removes the string "Bilbo"
hobbitset.add("Galadriel") #it adds the string "Galadriel"
new_set=set(["Saruman","Frodo","Gandalf"]) #it creates another set with new elements
hobbitset.update(new_set) #it is used for adding all the elements included in new_set
print(hobbitset)

@lisasiurina
Copy link

set(['Bilbo', 'Merry', 'Pippin', 'Sam', 'Frodo'])
my_set = set()
my_set.add("Bilbo")
my_set.add("Frodo")
my_set.add("Sam")
my_set.add("Pippin")
my_set.add("Pippin")
my_set.add("Merry")
my_set.remove("Bilbo") #this removes 'Bilbo" from the set
my_set.add("Galadriel") #this adds "Galadriel" to the set
my_set.update(set({"Saruman", "Frodo", "Gandalf"})) #adds all the elements included in to the my_set accept for "Frodo" which has been already added to the set
print (my_set)

output set(['Pippin', 'Galadriel', 'Sam', 'Frodo', 'Merry', 'Gandalf', 'Saruman'])

@tceron
Copy link

tceron commented Nov 30, 2018

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

my_set{'Bilbo', 'Merry', 'Pippin', 'Sam', 'Frodo'}
my_set.remove('Bilbo') #removes the item 'Bilbo'
my_set.add('Galadriel') #adds the item 'Galafriel'
my_set.update(set({'Saruman', 'Frodo', 'Gandalf'})) #it adds them items 'Saruman, and 'Gandalf' to the list, it doesn't add 'Frodo' because it was already present in the list.

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

@MilenaCorbellini
Copy link

esercizio 2
Last operation doesen't add "Frodo" because it's already in the set.

@DavideApolloni
Copy link

DavideApolloni commented Dec 1, 2018

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

my_set.remove("Bilbo")
#"Bilbo" wears the one ring and disappears from the set
output: my_set({"Frodo", "Sam", "Pippin", "Merry"})

my_set.add("Galadriel")
#"Galadriel" joins the set while she is looking for Aragorn
output: my_set({"Frodo", "Sam", "Galadriel, "Pippin", "Merry"})

​my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
#"Saruman" and "Gandalf", after having enjoyed some fireworks, join the set. "Frodo" is not added, as he is already present
output: my_set({"Gandalf", "Saruman, "Frodo", "Sam", "Galadriel, "Pippin", "Merry"})

@Saraa04
Copy link

Saraa04 commented Dec 1, 2018

Considering the first exercise:

the_hobbits = set()
the_hobbits.add("Bilbo")
the_hobbits.add("Frodo")
the_hobbits.add("Sam")
the_hobbits.add("Pippin")
the_hobbits.add("Merry")
print(the_hobbits)

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 set became:
# set ({"Frodo", "Sam", "Pippin", "Merry"})

the_hobbits.add("Galadriel") # this adds "Galadriel" to the set
# now the_hobbits set contains:
# set ({"Frodo", "Sam", "Pippin", "Merry", "Galadriel"})

the_hobbits.update(set({"Saruman", "Frodo", "Gandalf"}))
# it updates the_hobbits set
# it does not add the element "Frodo" to the set because it was already included

print(the_hobbits)

Output: set({'Galadriel', 'Gandalf', 'Pippin', 'Frodo', 'Sam', 'Saruman', 'Merry'})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Exercise The exercises that are introduced in the lectures.
Projects
None yet
Development

No branches or pull requests