Let's say I have a dictionary:
dict1 = {"Jim": "y", "Bob": "y", "Ravioli": "n"} # etc.
I want to print out all the keys with the value "y" (i.e: "Jim", "Bob"). How do I achieve this (in the simplest way possible)?
Let's say I have a dictionary:
dict1 = {"Jim": "y", "Bob": "y", "Ravioli": "n"} # etc.
I want to print out all the keys with the value "y" (i.e: "Jim", "Bob"). How do I achieve this (in the simplest way possible)?
You can use this:
[k for k, v in dict1.items() if v == 'y']
Result:
['Bob', 'Jim']