+ 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

25th Jun 2016, 5:26 PM
Jamie Florence
Jamie Florence - avatar
2 Respuestas
+ 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.
25th Jun 2016, 10:22 PM
Lari Liuhamo
Lari Liuhamo - avatar
0
That makes it difficult it find all the people that are 25 without at least 2 arrays.
26th Jun 2016, 4:31 AM
Roman Sill
Roman Sill - avatar