Open essepuntato opened 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)
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'}}
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")
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
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()
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'}}
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'}}
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'}
set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"}) set_magician = set({"Saruman", "Gandalf"})
lotr = dict() lotr["hobbits"] = set_hobbit lotr["magician"] = set_magician
my_action_figures = dict()
my_action_figures["hobbit"] = set({"Frodo", "Sam", "Pippin", "Merry"})
my_action_figures["magician"] = set({"Saruman", "Gandalf"})
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'}}
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)
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)
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'])}
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)
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)
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'}}
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 setset({"Frodo", "Sam", "Pippin", "Merry"})
, andset_magician
defined asset({"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"
.