-
Notifications
You must be signed in to change notification settings - Fork 0
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
Comments
My set = {"Gandalf", "Merry", "Sam", "Pippin", "Frodo", "Saruman", "Galadriel"} 1st method:
2nd method:
Output:
|
|
set_hobbit = {"Frodo", "Sam", "Pippin", "Merry"} my_dict = dict() Output: |
|
|
|
|
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'}} |
|
# 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'}} |
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'}} |
|
set_hobbit = {"Frodo", "Sam", "Pippin", "Merry"} |
|
my_dict = {"hobbit": {"Frodo", "Sam", "Pippin", "Merry"}, "magician": {"Saruman", "Gandalf"}} |
set_hobbit = set() set_magician = set() my_dict = dict() print(my_dict) my_dict={'hobbit': {'Sam', 'Pippin', 'Frodo', 'Merry'}, 'magician': {'Gandalf', 'Saruman'}} |
|
set_hobbit = {"Frodo", "Sam", "Pippin", "Merry"} lord_dictionary = dict() get_hobby = lord_dictionary.get("hobbit") print(get_hobby) |
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"
.The text was updated successfully, but these errors were encountered: