I have a dictionary which vlaues are list type and they are unique for each key.
d = {'key1': [1,2,3], 'key2': [4,5,6], 'key3': [7,8,9]}
And I have a variable called a = 3
. Now I want to find the key corresponding to this variable.
Thanks for help.
CodePudding user response:
required_key = None
for key,value in d.items():
if a in value:
required_key = key
break
print(required_key)