As mentioned in other answers, what you're asking for can be solved by looping over features
and checking if the desired string is in any of the lists. For instance:
def get_keys(features, value):
return tuple(
k
for k, values in features.items()
if value in values
)
print(get_keys(features, 'kamras')) # prints ("CAMERA",)
Or, if you want a single key, get_keys(features, 'kamras')[0]
.
However, if you're going to do this often, it would be better to invert your dictionary beforehand creating a new inverted
dict:
inverted = {
value: key
for key, values in features.items()
for value in values
}
print(inverted) # prints {'cam': 'CAMERA', 'Cam': 'CAMERA', 'camera': 'CAMERA', 'cameras': 'CAMERA', 'kameras': 'CAMERA', 'kamras': 'CAMERA', 'batterie': 'BATTERY', 'battery': 'BATTERY'}
This way, you can simply write:
print(inverted['kamra']) # prints "CAMERA"