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 15, 2023 · 20 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".

@Liber-R
Copy link

Liber-R commented Nov 15, 2023

Screenshot 2023-11-15 102739

@Asemica-me
Copy link

My set = {"Gandalf", "Merry", "Sam", "Pippin", "Frodo", "Saruman", "Galadriel"}

1st method:

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

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

2nd method:

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

Output:

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

@valentinabertelli
Copy link

my_set = set({"Frodo", "Pippin", "Saruman", "Galadriel", "Gandalf", "Sam", "Merry"})
set_hobbit = set()
set_hobbit.update(set({"Frodo", "Sam", "Pippin", "Merry"}))
set_magician = set()
set_magician.update(set({"Saruman", "Gandalf"}))
my_dict = dict()
my_dict["hobbit"] = set_hobbit
my_dict["magician"] = set_magician
#my_dict became:
#dict({'hobbit': {'Pippin', 'Merry', 'Frodo', 'Sam'}, 'magician': {'Gandalf', 'Saruman'}})

@Alice-Ant
Copy link

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

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

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

@katyakrsn
Copy link

set_hobbit = {"Frodo", "Sam", "Pippin", "Merry"}
set_magician = {"Saruman", "Gandalf"}
characters = {"hobbit": set_hobbit, "magicians": set_magician}
print(characters)

@ThIheb
Copy link

ThIheb commented Nov 15, 2023

set_hobbit = set({"Frodo","Sam","Pippin","Merry"})
set_magician = set({"Saruman","Gandalf"})
Lor_dict = dict()
Lor_dict["Hobbit"] = set_hobbit
Lor_dict["Magician"] = set_magician
print(Lor_dict)

#The outputwould be {'Hobbit': {'Merry', 'Pippin', 'Frodo', 'Sam'}, 'Magician': {'Gandalf', 'Saruman'}}

@qwindici
Copy link

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

my_dict = {"hobbit": set_hobbit, "magician": set_magician}

@krzywonos
Copy link

set_hobbit = {"Frodo", "Sam", "Pippin", "Merry"};
set_wizard = {"Saruman", "Gandalf"};
lotr_dict = {};
lotr_dict["hobbits"] = set_hobbit;
lotr_dict["wizards"] = set_wizard;
print(lotr_dict);
# {'hobbits': {'Merry', 'Sam', 'Frodo', 'Pippin'}, 'wizards': {'Saruman', 'Gandalf'}}

@MariaFrancesca6
Copy link

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)
my_dict = {'hobbit': {'Merry', 'Pippin', 'Sam', 'Frodo'}, 'magician': {'Gandalf', 'Saruman'}}

@rufferbaraldi
Copy link

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

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

@enricabruno
Copy link

enricabruno commented Nov 18, 2023

# creation of the first set
set_hobbit = ({"Frodo", "Sam", "Pippin", "Merry"})
# creation of the second set
set_magician = ({"Saruman", "Gandalf"})
# creation of the dictionary
hobbit_magician_dict = dict()
hobbit_magician_dict["hobbit"] = set_hobbit
hobbit_magician_dict["magician"] = set_magician
# the dictionary containing the two pairs
print(hobbit_magician_dict)

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

@frammenti
Copy link

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

#Method 1
my_dict = {}
my_dict["hobbit"] = set_hobbit
my_dict["magician"] = set_magician

# Method 2
my_dict = {"hobbit": set_hobbit, "magician": set_magician}

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

@alicepiazzi
Copy link

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

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

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

print(my_dict)
my_dict = {'hobbit': {'Merry', 'Pippin', 'Sam', 'Frodo'}, 'magician': {'Gandalf', 'Saruman'}}

@saramadonia
Copy link

set_hobbit = {"Frodo", "Sam", "Pippin", "Merry"}
set_magician = {"Saruman", "Gandalf"}
my_dict = {hobbits : set_obbit, magician : set_magician}

@simocasaz
Copy link

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

@matildepassafaro
Copy link

set_hobbit = {"Frodo", "Sam", "Pippin", "Merry"}
set_magician = {"Saruman", "Gandalf"}
# create a dictionary
my_dict = dict()
# add key-value pairs
my_dict["hobbit"] = set_hobbit
my_dict["magician"] = set_magician
print(my_dict)

my_dict = {"hobbit": {"Frodo", "Sam", "Pippin", "Merry"}, "magician": {"Saruman", "Gandalf"}}

@Chiaramartina
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)

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

@Sergpoipoip
Copy link

set_hobbit = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
set_magician = {"Saruman", "Gandalf"}
characters = {'hobbit': set_hobbit, 'magician': set_magician}

@CarlaMenegat
Copy link

Captura de Tela 2023-11-19 às 20 16 54

@annapasetto0
Copy link

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

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

get_hobby = lord_dictionary.get("hobbit")
get_magician = lord_dictionary.get("magician")

print(get_hobby)
print(get_magician)

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