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

Open
essepuntato opened this issue Nov 19, 2024 · 15 comments
Open
Labels
exercise Exercise

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 Exercise label Nov 19, 2024
@lisitein
Copy link

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

@KikaYang
Copy link

截屏2024-11-20 17 23 10

@yutong316
Copy link

image

@rumana-mh
Copy link

Screenshot 2024-11-20 232514
I didn't add the extra "set " parenthesis in the last line of instructions and the code worked.. But I was wondering if there was any reason why you added it.. or is it correct as well?

@maridematteis
Copy link

Screenshot 2024-11-21 alle 16 52 38

@shiho1000
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)

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

@arinee01
Copy link

Снимок экрана 2024-11-22 в 12 07 36

@ValkyrieCain9
Copy link

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

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

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

@martinamrc
Copy link

martinamrc commented Nov 24, 2024

my_set.remove('Bilbo')      # after this the element 'Bilbo' from the set will be removed 
my_set.add('Galadriel')       # after this the element 'Galadriel' will be added to the set
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))       # this will update my_set with the elements of the new set, but one, which is 'Frodo', since the element would be repeated

print(my_set)

Screenshot 2024-11-24 alle 14 56 29

@theair-hub
Copy link

image

@Maryamdadras
Copy link

#Step 1
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
print(my_set)
#out put: {'Bilbo', 'Frodo', 'Sam', 'Pippin', 'Merry'}

#Step 2: remove "Bilbo"
my_set.remove("Bilbo")
print(my_set)
#out put: {'Frodo', 'Sam', 'Pippin', 'Merry'}

#Step 3: add "Galadriel"
my_set.add("Galadriel")
print(my_set)
#out put: {'Frodo', 'Sam', 'Pippin', 'Merry', 'Galadriel'}

#Step 4: update with {"Saruman", "Frodo", "Gandalf"}
my_set.update({"Saruman", "Frodo", "Gandalf"})
print(my_set)
#out put: {'Frodo', 'Sam', 'Pippin', 'Merry', 'Galadriel', 'Saruman', 'Gandalf'}

@ERendall
Copy link

image

@nicoldamelio
Copy link

Screenshot 2024-11-30 alle 21 20 51

@martinaucch
Copy link

my_first_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
print(my_first_set)
my_first_set.remove("Bilbo")
print(my_first_set)
my_first_set.add("Galadriel")
print(my_first_set)
my_first_set.update(set({"Saruman", "Frodo", "Gandalf"}))
print(my_first_set)
Screenshot 2024-12-08 alle 23 50 02

@romashovar
Copy link

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

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

No branches or pull requests

17 participants