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

Open
essepuntato opened this issue Nov 9, 2021 · 21 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"})).

@11051620
Copy link

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

@chloeppd
Copy link

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

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

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

@katya-avem
Copy link

  1. my_set.remove("Bilbo") --> {'Pippin', 'Merry', 'Sam', 'Frodo'}
  2. my_set.add("Galadriel") --> {'Pippin', 'Merry', 'Galadriel', 'Sam', 'Frodo'}
  3. my_set.update(set({"Saruman", "Frodo", "Gandalf"})) --> {'Saruman', 'Sam', 'Frodo', 'Pippin', 'Galadriel', 'Merry', 'Gandalf'}

@elizastuglik
Copy link

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

@tommasobattisti
Copy link

my_set will contain 'Sam', 'Gandalf', 'Galadriel', 'Frodo', 'Saruman', 'Pippin' and 'Merry'

@martasoricetti
Copy link

image

@OrsolaMBorrini
Copy link

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

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

my_set.add("Galadriel")
# my_set = {"Frodo", "Galadriel", "Sam", "Pippin", "Merry"} or my_set = {"Frodo", "Sam", "Pippin", "Galadriel", "Merry"} or the other possible combinations
# The position of the new element "Galadriel" is irrelevant as the elements in a set are unordered

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

@Bianca-LM
Copy link

my_set.remove("Bilbo")
#now my_set = {"Frodo", "Sam", "Pippin", "Merry"}. It has been removed the only possible occurence of Biblo, 
#because the same element can't be in the set more than one time

my_set.add("Galadriel")
#"Galadriel" is added to the set in a not fixed position, established by any order, 
#so my_set = {"Frodo", "Sam", "Pippin", "Merry", "Galadriel"}

​my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
#"Saruman" and "Gandalf" are added to the set as "Galadriel" previously. "Frodo" is already contained and 
#it can't be added more than one time. Now my_set = {"Frodo", "Sam", "Pippin", "Merry", "Galadriel", "Saruman", "Gandalf"}

@giorgimariachiara
Copy link

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

@olgagolgan
Copy link

image
image

@GinevraBotto
Copy link

‘’’
my_set.remove("Bilbo")
#We are removing Bilbo from the list

Set={'Frodo', 'Merry', 'Pippin', 'Sam'}

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

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

Set={'Frodo', 'Merry', ‘Galadriel’, 'Pippin', 'Sam', 'Saruman', 'Gandalf' } #frodo just one time because a set has no-repeatable elements

‘’’

@ManueleVeggi
Copy link

The set is composed by the followings strings: "Frodo", "Merry", "Pippin", "Sam", "Bilbo".

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

@francescabudel
Copy link

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

print(lotr_set)

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

@SaraVell1
Copy link

image

@angstigone
Copy link

Schermata 2021-11-14 alle 12 36 39

Schermata 2021-11-12 alle 17 42 24

@AmeliaLamargese
Copy link

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

@federicabonifazi
Copy link

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

@AnastasiyaSopyryaeva
Copy link

Input

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

my_set.remove("Bilbo")
print(my_set)

my_set.add("Galadriel")
print(my_set)

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

Output

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

@sanyuezoe
Copy link

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

@teragramgius
Copy link

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

@GaiaOrtona
Copy link

my_second_set.remove("Bilbo") print(my_second_set) #the result is {"Pippin", "Frodo", "Sam", "Merry"} my_second_set.add("Galadriel") print(my_second_set) #the result is {"Frodo", "Sam", "Merry", "Galadriel", "Pippin"} my_second_set.update(set({"Saruman", "Frodo", "Gandalf"})) print(my_second_set) #the result is {"Sam", "Gandalf", "Saruman", "Merry", "Galadriel", "Pippin", "Frodo"}

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