Is there any straightforward way of finding a key by knowing the value within a dictionary?
All I can think of is this:
key = [key for key, value in dict_obj.items() if value == 'value'][0]
Is there any straightforward way of finding a key by knowing the value within a dictionary?
All I can think of is this:
key = [key for key, value in dict_obj.items() if value == 'value'][0]
Maybe a dictionary-like class such as
DoubleDict
down below is what you want? You can use any one of the provided metaclasses in conjuction withDoubleDict
or may avoid using any metaclass at all.This is literally it