我有两个词典列表,如下所示
devices = [
{'a': 'b', 'c': 'd'},
{'a': 'e', 'f': 'g'},
{'h': 'i', 'j': 'k'}
]
alldicts = [
{'a': {'eth1': 'b', 'eth2': 'e'}},
{'c': {'eth1': 'd', 'eth2': 'o', 'eth3': 'q'}},
{'f': {'eth1': 'g'}},
{'h': {'eth1': 'i'}},
{'j': {'eth1': 'k'}}
]
我想要有DICT的输出列表,这样新的列表将有来自设备的所有项目,但将替换来自所有DICTS的值.因此,所需的输出应该如下所示
帖子主题:Re:Колибри
final_list = [
{'a': 'eth1', 'c': 'eth1'},
{'a': 'eth2', 'f': 'eth1'},
{'h': 'eth1', 'j': 'eth1'}
]
下面是我正在try 的代码,但它没有给我所需的输出
final_int = []
for each in devices:
for i,j in each.items():
for each_dict in alldicts:
for k,l in each_dict.items():
for a,b in l.items():
if b == j and i == k:
final_int.append({i:a})