Open essepuntato opened 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
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'}}
set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician = set({"Saruman", "Gandalf"})
my_dict = {"hobbit": set_hobbit, "magician": set_magician}
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)
set_hobbit = {'Frodo', 'Sam', 'Pippin', 'Merry'}
set_magician = {'Saruman','Gandalf'}
my_dict= {"hobbit": set_hobbit, "magician": set_magician}
set_hobbit = {'Frodo', 'Sam', 'Pippin', 'Merry'}
set_magician = {'Saruman', 'Gandalf'}
dict_LOR = {
'hobbit': set_hobbit,
'magician': set_magician
}
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_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
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'}}
# 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)
`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)`
# 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)
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)
# 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'}}
`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)
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'}}
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'}}
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'}}
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
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)
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 setset({"Frodo", "Sam", "Pippin", "Merry"})
, andset_magician
defined asset({"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"
.