两个字典分别为:
dict1 = {'providers': 'aetna, united_health, cardinal'}
dict2 = {'aetna': ['13e2345', '13e2346'], 'bcbs': ['901E12'], 'united_health': []}
如果与dict1中的数据匹配,我需要比较两个字典并打印dict2中的数据。
预期输出:
{'aetna': ['13e2345', '13e2346'], 'united_health': []}
答案 0 :(得分:3)
您可以使用简单的字典理解:
{'aetna': ['13e2345', '13e2346'], 'united_health': []}
输出:
{{1}}
答案 1 :(得分:0)
dict1 = {'providers': 'aetna, united_health'}
dict2 = {'aetna': ['13e2345', '13e2346'], 'bcbs': ['901E12'], 'united_health': []}
result = {key: dict2.get(key, []) for key in dict1.get('providers').split(', ')}
{'aetna': ['13e2345', '13e2346'], 'united_health': []}