comp-think / 2018-2019

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. 2018/2019).
Other
30 stars 8 forks source link

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

Open essepuntato opened 5 years ago

essepuntato commented 5 years ago

Suppose that all the elements in the set returned by the second exercise have been organised in two different sets, i.e. 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 associate the set of hobbits with the key "hobbit", and the other that associates the set of magicians with the key "magician".

andreamust commented 5 years ago
set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician = set({"Saruman", "Gandalf"})
first_dict = dict()  # this creates a new dictionary
first_dict["hobbit"] = set_hobbit
first_dict["magician"] = set_magician
print(first_dict)

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

bluebell94 commented 5 years ago

set_hobbits=({"Frodo","Sam","Pippin","Merry"}) set_magicians=({"Saruman","Gandalf"}) dict_protagonists=dict() dict_protagonists["hobbit"]=set_hobbits dict_protagonists["magician"]=set_magicians print(dict_protagonists)

At the end to each of the names in the set_hobbits is assigned key "hobbit", correspondingly to each name in the set_magicians is asssigned - "magician". {'hobbit': {'Sam', 'Frodo', 'Merry', 'Pippin'}, 'magician': {'Saruman', 'Gandalf'}}

beccadelbens commented 5 years ago

set_hobbit = set()

set_hobbit({"Frodo", "Sam", "Pippin", "Merry"})

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

set_magician = set()

set_magician({"Saruman", "Gandalf"})

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

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


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

set_magician = set() set_magician = ({"Saruman", "Gandalf"})

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

EleonoraPeruch commented 5 years ago
my_dict = dict() # create a new dictionary

# first pair
for i in set_hobbit:
    my_dict["hobbit"] = i   # associate each item in set_hobbit with the key "hobbit"

# second pair
for i in set_magician:
    my_dict["magician"] = i # associate each item in set_magician with the key "magician"

return dict()
simayguzel commented 5 years ago
hobbitset = set({"Frodo", "Sam", "Pippin", "Merry"})
hobbitmagician = set({"Saruman", "Gandalf"})
mydict = dict()
mydict['hobbits'] = hobbitset
mydict['magicians'] = hobbitmagician
for each in hobbitset:
    mydict['hobbits'].update
for each in hobbitmagician:
    mydict['magicians'].update
print(mydict)
output = {'hobbits': {'Merry', 'Sam', 'Pippin', 'Frodo'}, 'magicians': {'Gandalf', 'Saruman'}}
leticiasandra commented 5 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 return_my_dict = dict() print(my_dict) output = {'hobbits': {'Merry', 'Frodo', 'Sam', 'Pippin'}, 'magician': {'Saruman', 'Gandalf'}}

delfimpandiani commented 5 years ago
set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"})
# my_set({"Frodo", "Sam", "Pippin", "Merry", "Galadriel", "Saruman", "Gandalf"})

set_magician = set({"Saruman", "Gandalf"})

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

print(fantasy_dict["hobbit"])
# this returns {'Merry', 'Sam', 'Frodo', 'Pippin'}

print(fantasy_dict["magician"])
# this returns {'Saruman', 'Gandalf'}
MattiaSpadoni commented 5 years ago

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

quest Create a dictionary with 2 key: "hobbit" and "magician" that contain the proper values

lotr = dict() lotr["hobbits"] = set_hobbit lotr["magician"] = set_magician

what are you doing here? Take you sword and you horse, time to go to Pelennor's field.

just an historical curiosity, something like the battle of Pelennor's field is happened in reality.

in 955 the Holy Roman Emperor Oton I defeted a huge Hungarian horde in the Lechfeld batte with a #cavalry charge, the heavy cavarly charge should be very similar to the cavalry charge of LOTR

SeverinJB commented 5 years ago
my_action_figures = dict()

my_action_figures["hobbit"] = set({"Frodo", "Sam", "Pippin", "Merry"})
my_action_figures["magician"] = set({"Saruman", "Gandalf"})
ilsamoano commented 5 years ago
set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician = set ({"Saruman", "Gandalf"})

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

print(LOTR)

# {'hobbit': {'Sam', 'Pippin', 'Frodo', 'Merry'}, 'magician': {'Gandalf', 'Saruman'}}
Totaro1996 commented 5 years ago

set_hobbit=set(["Frodo","Sam", "Pippin", "Merry"]) set_magician=set(["Saruman","Gandalf"])

first_dictionary=dict() first_dictionary["name"]="hobbit" first_dictionary["set"]=set_hobbit

second_dictionary=dict() second_dictionary["name_two"]="magician" second_dictionary["set_two"]=set_magician

first_dictionary.update(second_dictionary) print(first_dictionary)

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

a_day_may_come_when_the_courage_of_men_fails = dict()

a_day_may_come_when_the_courage_of_men_fails ["hobbits"] = set_hobbit
a_day_may_come_when_the_courage_of_men_fails ["magicians"] = set_magician

print(a_day_may_come_when_the_courage_of_men_fails)
lisasiurina commented 5 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 print (my_dict)

output {'magician': set(['Gandalf', 'Saruman']), 'hobbit': set(['Frodo', 'Pippin', 'Sam', 'Merry'])}

tceron commented 5 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)

MilenaCorbellini commented 5 years ago

esercizio3

DavideApolloni commented 5 years ago

set_hobbits = set({"Frodo", "Sam", "Pippin", "Merry"}) set_magicians = set({"Saruman", "Gandalf"})

middle_earth = dict() middle_earth["hobbits"] = set_hobbits middle_earth["magicians"] = set_magicians

print(middle_earth)

Saraa04 commented 5 years ago

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

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

print(my_first_dictionary)

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