comp-think / 2020-2021

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. 2020/2021).
14 stars 9 forks source link

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

Open essepuntato opened 4 years ago

essepuntato commented 4 years ago

Suppose to organise some of the elements in the set returned by the second exercise in two different sets: set_hobbit that refers to the set set({"Frodo", "Sam", "Pippin", "Merry"}), and set_magician defined as set({"Saruman", "Gandalf"}). Create a dictionary containing two pairs: one that associates the set of hobbits with the key "hobbit", and the other that associates the set of magicians with the key "magician".

IlaRoss commented 4 years ago
set_hobbit = set({'Frodo', 'Sam', 'Pippin', 'Merry'})
set_magician = set({'Saruman','Gandalf'})

my_dict = dict()
my_dict['hobbit'] = set_hobbit
my_dict['magician'] = set_magician
penelopelask commented 4 years ago

set_hobbit = set()
set_hobbit.add("Frodo")
set_hobbit.add("Sam")
set_hobbit.add("Pippin")
set_hobbit.add("Merry")

set_magician = set()
set_magician.add("Saruman")
set_magician.add("Gandalf")

mydict = dict()
mydict["hobbit"] = set_hobbit
mydict["magician"] = set_magician

print(set_hobbit)
print(set_magician)
print(mydict)

{'Merry', 'Frodo', 'Sam', 'Pippin'}
{'Saruman', 'Gandalf'}
{'hobbit': {'Merry', 'Frodo', 'Sam', 'Pippin'}, 'magician': {'Saruman', 'Gandalf'}}
gabrielefiorenza commented 4 years ago
set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician = set({"Saruman", "Gandalf"})
my_dict = {"hobbit": set_hobbit, "magician": set_magician}
ChiaraCati commented 4 years ago
set_hobbit = set()
set_hobbit.add('Frodo')
set_hobbit.add('Sam')
set_hobbit.add('Pippin')
set_hobbit.add('Merry')

set_magician = set()
set_magician.add('Saruman')
set_magician.add('Gandalf')

lotr_dict = dict()
lotr_dict['hobbit'] = set_hobbit
lotr_dict['magician'] =set_magician

print(lotr_dict)
dbrembilla commented 4 years ago
set_hobbit = {'Frodo', 'Sam', 'Pippin', 'Merry'}
set_magician = {'Saruman','Gandalf'}
my_dict= {"hobbit": set_hobbit, "magician": set_magician}
edoardodalborgo commented 4 years ago
set_hobbit = {'Frodo', 'Sam', 'Pippin', 'Merry'}
set_magician = {'Saruman', 'Gandalf'}
dict_LOR = {
'hobbit': set_hobbit,
'magician': set_magician
}
giorgiasampo commented 4 years ago

set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"}) set_magician = set({"Saruman", "Gandalf"})

my_dictionary = dict () my_dictionary ["hobbit"] = set_hobbit my_dictionary ["magician"] = set_magician

print (my_dictionary)

GiuliaMenna commented 4 years ago
set_hobbit = set({"Frodo","Sam","Pippin","Merry"})
set_magician = set({"Saruman","Gandalf"})

my_dict = dict()
my_dict["hobbit"] = set_hobbit
my_dict["magician"] = set_magician
output = my_dict
LuisAmmi commented 4 years ago

char_set = {'Sam', 'Galadriel', 'Saruman', 'Frodo', 'Merry', 'Gandalf', 'Pippin'}
set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician = set({"Saruman", "Gandalf"})

rings_dic = dict()
rings_dic["hobbit"] = set_hobbit
rings_dic["magician"] = set_magician

print(rings_dic) 
# print {'hobbit': {'Frodo', 'Sam', 'Merry', 'Pippin'}, 'magician': {'Gandalf', 'Saruman'}}
fcagnola commented 4 years ago
# Suppose to organise some of the elements in the set returned by the second exercise
# in two different sets: set_hobbit that refers to the set set({"Frodo", "Sam", "Pippin", "Merry"}),
# and set_magician defined as set({"Saruman", "Gandalf"}).
# Create a dictionary containing two pairs: one that associates the set of hobbits with the key "hobbit",
# and the other that associates the set of magicians with the key "magician".

set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician = set({"Saruman", "Gandalf"})

lotr_dictionary = dict() # create an empty dictionary object
lotr_dictionary["hobbit"] = set_hobbit # assign the existing set to the key "hobbit" in the new dictionary
lotr_dictionary["magician"] = set_magician # assign the existing set to the key "magician" in the new dictionary
print(lotr_dictionary)
SofiBar commented 4 years ago

`my_set = ({"Frodo", "Sam", "Pippin", "Mary", "Saruman", "Gandalf"}) my_set.remove("Saruman") my_set.remove("Gandalf") set_hobbit = my_set set_magician = ({"Saruman", "Gandalf"})

my_dictionary = dict() my_dictionary = ({"hobbit":set_hobbit, "magician":set_magician})

print(my_dictionary)`

yunglong28 commented 4 years ago
# Creating two separate sets
set_hobbit = {"Frodo", "Sam", "Pippin", "Merry"}
set_magicians = {"Gandalf", "Saruman"}

# Creating a dictionary
lotr_dict = {"hobbit": '{"Frodo", "Sam", "Pippin", "Merry}', "magicians": '{"Gandalf","Saruman"}'}

print(lotr_dict)
SarahTew commented 4 years ago
set_hobbit={"Frodo", "Sam", "Pippin", "Merry"}
set_magician={"Saruman", "Gandalf"}
lotr_dict=dict()
lotr_dict["hobbit"]=set_hobbit
lotr_dict["magician"]=set_magician

print(lotr_dict["hobbit"])
print(lotr_dict["magician"])
print(lotr_dict)
vanessabonanno commented 4 years ago
# I create two sets of elements
set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician = set({"Saruman", "Gandalf"})

# I initialise an empty dictionary
lotr_dictionary = dict()

# I add the keys of the dictionary. Their relative values are the sets created before
lotr_dictionary["hobbit"] = set_hobbit
lotr_dictionary["magician"] = set_magician

print(lotr_dictionary) 
# output: {'hobbit': {'Merry', 'Pippin', 'Sam', 'Frodo'}, 'magician': {'Saruman', 'Gandalf'}}
Camillaneri commented 4 years ago

`set_hobbit = set(({"Frodo", "Sam", "Pippin", "Merry"})) set_magician = set(({"Saruman", "Gandalf"}))

lotr_dict = dict() lotr_dict["hobbits"] = set_hobbit lotr_dict["magicians"] = set_magician

print(lotr_dict)

output {'hobbit': {'Frodo', 'Pippin', 'Sam', 'Merry'}, 'magician': {'Saruman', 'Gandalf'}}`

AlessandraFa commented 4 years ago
set_hobbit = set({'Bilbo', 'Pippin', 'Sam', 'Merry', 'Frodo'})
set_magician = set({"Saruman", "Gandalf"})
lotr_dict = dict()
lotr_dict["hobbit"] = set_hobbit
lotr_dict["magician"] = set_magician

print(lotr_dict)
# Output: {'hobbit': {'Bilbo', 'Pippin', 'Sam', 'Frodo', 'Merry'}, 'magician': {'Gandalf', 'Saruman'}}
LauOcchipinti commented 4 years ago

set_hobbit = set() set_hobbit.add ("Frodo") set_hobbit.add ("Sam") set_hobbit.add ("Pippin") set_hobbit.add ("Marry") print(set_hobbit) {'Sam', 'Frodo', 'Pippin', 'Marry'} set_magician = set() set_magician.add ("Gandalf") set_magician.add("Saruman") print(set_magician) {'Gandalf', 'Saruman'} dictionary = dict() dictionary["hobbit"]= set_hobbit dictionary ["magician"]=set_magician print (dictionary) {'hobbit': {'Sam', 'Frodo', 'Pippin', 'Marry'}, 'magician': {'Gandalf', 'Saruman'}}

AleRosae commented 4 years ago
set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician = set({"Saruman", "Gandalf"})

LOTR_dict = dict()
LOTR_dict["hobbit"] = set_hobbit
LOTR_dict["magician"] = set_magician

print(LOTR_dict) #returns {'hobbit': {'Sam', 'Merry', 'Frodo', 'Pippin'}, 'magician': {'Gandalf', 'Saruman'}}
SusannaPinotti commented 4 years ago
set_hobbit= set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician = set({"Saruman", "Gandalf"})

lotr_dict = dict()
lotr_dict["hobbits"] = set_hobbit
lotr_dict["magicians"]= set_magician
AlessandroBertozzi commented 4 years ago
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}

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

# organise information from previous exercise
set_magician = set()
set_hobbit = set()
for name in my_set:
    if name == "Saruman" or name == "Gandalf":
        set_magician.add(name)
    else:
        set_hobbit.add(name)

# creation of the dictionary
my_Lotr_dictionary = {}
my_Lotr_dictionary["hobbit"] = set_hobbit
my_Lotr_dictionary["magician"] = set_magician
print(my_Lotr_dictionary)