Dictionaries
Dictionaries are very similar to Lists in Python. The only difference is that the keys (indicies) of a dictionary can be any immutable data type. This means that your indicies can be strings now! This is incredibly useful, but can open a brand new can of worms.
For each of the following, describe what you expect the program to output.
-
my_dictionary = {"Smith": "120B", "Bouchard": "120A"} print(my_dictionary["Smith"])
-
my_dictionary = {"Smith": "120B", "Bouchard": "120A"} print(my_dictionary["Shende"])
-
my_dictionary = {"Smith": "120B", "Bouchard": "120A"} print(my_dictionary["Bouchard"])
-
my_dictionary = {"Smith": "120B", "Bouchard": "120A"} my_dictionary["Shende"] = "250A" print(my_dictionary["Shende"])
-
my_dictionary = {"Smith": "120B", "Bouchard": "120A", "Shende": "250A"} print(my_dictionary.keys())
-
my_dictionary = {"Smith": "120B", "Bouchard": "120A", "Shende": "250A"} print(my_dictionary.values())
-
my_dictionary = {"Smith": "120B", "Bouchard": "120A", "Shende": "250A"} del my_dictionary["Bouchard"] print(my_dictionary.keys())
-
my_dictionary = {"Smith": "120B", "Bouchard": "120A", "Shende": "250A"} del my_dictionary["Minton"] print(my_dictionary.keys())