How to get all the keys with the same values?
📁 dictionary, Advanced Python Topics
There is a dictionary: mydict = {'Main': 'Open', 'Second': 'Close', 'Third': 'Open'}. It is necessary to get all the keys with the value 'Open'.
>>> print(mydict)
{'Main': 'Open', 'Second': 'Close', 'Third': 'Open'}
>>> print(list(mydict.keys())[list(mydict.values()).index('Open')])
Main
It only displays Main. How to display all the keys with the value 'Open'?
No answers yet.
Log in to leave an answer