Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
essepuntato opened this issue Nov 14, 2022 · 17 comments
Open
Labels

Comments

@essepuntato
Copy link
Contributor

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

@n1kg0r
Copy link

n1kg0r commented Nov 14, 2022

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

lotr_dict = dict({'hobbit': set_hobbit, 'magician': set_magician})

@delete4ever
Copy link

lotr_dict={}
set_hobbit= set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician= set({"Saruman", "Gandalf"})
lotr_dict.update({"hobbit":set_hobbit})
lotr_dict.update({"magician":set_magician})

@EricaAndreose
Copy link

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("Galdalf")

lotr_dict = dict()

lotr_dict["hobbit"]=set_hobbit
lotr_dict["magician"]=set_magician

print(lotr_dict)

Terminal run: {'hobbit': {'Frodo', 'Sam', 'Pippin', 'Merry'}, 'magician': {'Saruman', 'Galdalf'}}

@lvcasmariani
Copy link

lotr_dict = dict()
lotr_dict["hobbit"] = "Frodo", "Sam", "Pippin", "Merry"
lotr_dict["magician"] = "Saruman", "Gandalf"

print(lotr_dict)

#now lotr_dict contains:
#{'hobbit': {'Frodo', 'Sam', 'Pippin', 'Merry'}, 'magician': {'Saruman', 'Gandalf'}}

@GaiaOrtona
Copy link

set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"}) set_magician = set({"Saruman", "Gandalf"}) my_first_dict = dict() my_first_dict["hobbit"] = set_hobbit my_first_dict["magician"] = set_magician print(my_first_dict)

@giorgiacrosilla
Copy link

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

@mjavadf
Copy link

mjavadf commented Nov 15, 2022

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

fellowship = {'hobbit': set_hobbit,
              'magician': set_magician}

@tiglio95
Copy link

set_hobbits = set({"Frodo", "Sam", "Pipin", "Merry"})
set_magicians = set({"Asurman", "Gandalf"})
new_dict = dict(({"Hobbit": set_hobbits, "magician":set_magicians}))
print(new_dict)

output: {'Hobbit': {'Pipin', 'Frodo', 'Merry', 'Sam'}, 'magician': {'Asurman', 'Gandalf'}}

@ranacoskun
Copy link

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

my_dict = dict({"hobbit":set_hobbit,"magician":set_magician})
#{'hobbit': {'Frodo', 'Merry', 'Pippin', 'Sam'}, 'magician': {'Saruman', 'Gandalf'}}

@lucia1299
Copy link

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

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

print(dict_tolkien)

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

@matteo-guenci
Copy link

matteo-guenci commented Nov 16, 2022

set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician = set({"Gandalf", "Saruman"})
dict = ({"hobbits" : set_hobbit, "magician" : set_magicians})
print(dict)

@corrado877
Copy link

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


hobbit_dict=dict()
magician_dict=dict()
hobbit_dict["Hobbits"]=set_hobbit
magician_dict["Magicians"]=set_magician

lotr_dict=dict()
lotr_dict.update(hobbit_dict)
lotr_dict.update (magician_dict)

print (lotr_dict)
{'Hobbits': {'Frodo', 'Pippin', 'Sam', 'Merry'}, 'Magicians': {'Saruman', 'Gandalf'}}

@SalvatoreDiMarzo
Copy link

my_set ={"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set.remove("Bilbo")
my_set.add("Galadriel")
my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"})
set_magician = set({"Saruman", "Gandalf"})
my_dict = dict({"Hobbit:": set_hobbit, "Magician:": set_magician})
print(my_dict)

Result
{'Hobbit:': {'Merry', 'Frodo', 'Sam', 'Pippin'}, 'Magician:': {'Saruman', 'Gandalf'}}

@ChiaraParravicini
Copy link

set_hobbit = {"Frodo", "Sam", "Pippin", "Merry"}
set_magician = {"Saruman", "Gandalf"}
lotr_characters_dict = dict()
lotr_characters_dict["hobbit"] = "Frodo", "Sam", "Pippin", "Merry"
lotr_characters_dict["magician"] = "Saruman", "Gandalf"

@eugeniavd
Copy link

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

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

#checking
print(ring_dict)

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

@essepuntato
Copy link
Contributor Author

Hi all,

Just a few comments:

  • @lvcasmariani and @ChiaraParravicini, you did not create sets, really... Try to run it in the terminal and see what happens when printing the final object
  • @GaiaOrtona, please, use the right environment for rendering the code (i.e. ```)

@alka2696
Copy link

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

print(my_dict)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests