My bad. I pasted the last question I asked instead of the one I meant.
Here's what I was going off of. Same dictionary, so:
Code: Select all
pet_dictionary = {"dogs": ["Yorkie", "Collie", "Bulldog"], "cats": ["Persian", "Scottish Fold", "Siberian"], "rabbits": ["Angora", "Holland Lop", "Harlequin"]}
print(pet_dictionary.get("dogs", 0))
#that returns
['Yorkie', 'Collie', 'Bulldog']
Coach:can the get method only retrieve one key?
There are multiple other ways of doing this but the last part isn't true/doesn't work.No, the get method can retrieve multiple keys.
The syntax for the get method is:
get(key, default=None)
The key parameter is the key that you want to retrieve. The default parameter is the value that will be returned if the key does not exist.
For example, the following code retrieves the value for the key "name" from the dictionary my_dictionary:
value = my_dictionary.get("name")
If the key "name" does not exist in the dictionary, the value None will be returned.
You can also use the get method to retrieve multiple keys at once. For example, the following code retrieves the values for the keys "name", "age", and "city" from the dictionary my_dictionary:
values = my_dictionary.get("name", "age", "city")
Probably could have been a better worded question on my part, because really I'm looking to retrieve multiple values using the keys. But it's still coming back with seemingly made up information.
