I have a list and dictionary
lis = ["abc","bcd fg","cda"]
dic = {1:"dcbagh",2:"cd abc", 3:"fg"}
I want to compare the list values with a dictionary values and return a new dictionary like below,
res_dic = {1:"none" ,2:"abc" , 3:"bcd fg"}
We need to return a corresponding string even if matches slightly. I have tried with the following method. But nothing worked out.
n = {}
for k,v in dic.items():
for i in lis:
if i==k:
n[k] = v
this is another method
n = {k: d[k] for k in d.keys() & set(lis)}
question from:https://stackoverflow.com/questions/65863973/compare-list-values-with-dictionories-python