I have the following dictionary. Each key contains a list of unique values:
d = {1:[10,11,12],2:[13,14],3:[15,16,17,18],4:[19],5:[20]}
I want to return the key for specified target value as per the example below (this does return the desired result).
keys = list(d.keys())
values_lst = list(d.values())
target_value = 20
for i,values in enumerate(values_lst):
if target_value in values:
index = i
keys[index]
5
However, is there a way to achieve this result without deploying the for loop (at least explicitly). The solution that I have does not feel particularly pythonic.
Thanks!