Consider the following dictionary.
dict = {
'key_1': ['name1', 'name2', 'name3'],
'key_2': ['name4', 'name5', 'name6']
}
Given a string called "name6", how to easy figure that this is belongs to "key_2" key with lesser looping. I have the following code, how can I optimize for time constraint of this. Above code is just an example, there are several such keys present in the dictionary.
dict = {
'key_1': ['name1', 'name2', 'name3'],
'key_2': ['name4', 'name5', 'name6']
}
output_key = None
for key in dict:
if 'name6' in dict[key]:
output_key = key
break