comp-think / 2019-2020

The GitHub repository containing all the material related to the Computational Thinking and Programming course of the Digital Humanities and Digital Knowledge degree at the University of Bologna (a.a. 2019/2020).
Other
12 stars 3 forks source link

Lecture "Organising information: unordered structures", exercise 2 #23

Open essepuntato opened 4 years ago

essepuntato commented 4 years ago

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

sntcristian commented 4 years ago
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 is now consisting in {"Frodo", "Pippin", "Sam", "Merry"}

my_set.add("Galadriel")
#my_set is now consisting in {"Frodo", "Pippin", "Sam", "Merry", "Galadriel"}

my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
#my_set is now consisting in {"Frodo", "Pippin", "Sam", "Merry", "Galadriel", "Gandalf", "Saruman"}
arcangelo7 commented 4 years ago
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set.remove("Bilbo") # it removes "Bilbo"
# my_set became:
# {'Sam', 'Frodo', 'Merry', 'Pippin'}
my_set.add("Galadriel") # It adds "Galadriel" to the set without any particular order
# my_set became:
# {'Sam', 'Frodo', 'Galadriel', 'Merry', 'Pippin'}
my_set.update(set({"Saruman", "Frodo", "Gandalf"})) # It only adds "Saruman" and "Gandalf", because "Frodo" is already included
# my_set became:
# {'Saruman', 'Sam', 'Frodo', 'Galadriel', 'Merry', 'Pippin', 'Gandalf'}
Vince2992 commented 4 years ago

Ex2_10

ariele-santello commented 4 years ago

Schermata 2019-11-06 alle 20 28 56

FrancescoFernicola commented 4 years ago

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

my_set.remove("Bilbo")
# this removes the element "Bilbo" from the set

my_set.add("Galadriel")
# this adds the element "Galadriel" to the set

my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
# this adds the element "Saruman" and "Gandalf" to the set
elisasilvad commented 4 years ago

Excercise 5 2

marcograsso commented 4 years ago

unordered_ex2

morinigiu commented 4 years ago
Schermata 2019-12-08 alle 17 14 30