0

How to find a key by value in list of values

items = ['itm1','itm2',:itm3','itm4'] Dict1 = { "key1" : ["w","itm1","g","j"] "key2" : ["o","l","itm2","m"] "key3" : ["v","itm3","y","u"] "key4" : ["e","d","x","itm4"] } # how should be this loop for itm in items: if itm in dict1: print (key)

19th Aug 2020, 8:13 AM
Houshyar
Houshyar - avatar
3 odpowiedzi
+ 1
Give this a try. for itm in items: for key in dict1: if itm in dict1[key]: print (f”{itm} , {key}”)
19th Aug 2020, 8:23 AM
Esch
Esch - avatar