我有两个字典,例如:
dict1 = {'Ron': ['Ronaldo', 'Ronald', 'Ron', 'Ronny'],
'John': ['Johnny', 'john', 'johnny Bravo'],
'Hard': ['Hardy', 'Hardy Boys', 'Hardness']}
dict2 = {'Ronald': ['America', 'New York'],
'Johnny': ['Canada', 'Ottawa']}
我想比较两个字典并提取 dict1 的“键”和dict2的值,当且仅当dict2的“键”与dict1的值匹配时!像:
resultant_dict = {'Ron' : ['America', 'New York'],
'John' : ['Canada', 'Ottawa']}
我已经尝试过嵌套循环并且能够获得所需的字典,但可以请有人通过 python 中的生成器帮助我做到这一点!谢谢
注意:DICT2 的 KEY 在 DICT1 的 VALUE 中只能是一个!