+ 3
So can you only call back the second part of the dictionary using the first or can you do it the opposite way round?
eg. rather than print(age("Matt")) to return 24 could you print(age(24)) to return Matt
2 odpowiedzi
+ 2
No, because it's not meant to work that way.
You see, in a dictionary each keyword must be unique so that they won't get mixed up, whereas the values can be anything, even duplicates of themselves.
Assume you had a dictionary like this:
guests = {"Michael": 25, "Steve": 26, "Laura": 25}
If you could search with values, the moment you searched for 25 would result in that you have two answers. That's not supposed to happen.
0
That makes it difficult it find all the people that are 25 without at least 2 arrays.