我有一个字典列表:
list_of_ds = [
{'a': [1, 2], 'b': [4, 5], 'c': [6, 7]},
{'a': [4], 'b': [56], 'c': [46]},
{'a': [92], 'b': [65], 'c': [43]}
]
我希望你能输出以下内容:
{'a': [1, 2, 4, 92], 'b': [4, 5, 56, 65], 'c': [6, 7, 46, 43]}
直到现在...
我尝试过
d_of_ds = reduce(lambda d1, d2: d1.update(d2), list_of_ds)
出现错误:AttributeError: 'NoneType' object has no attribute 'update'
我尝试了:
d_of_ds = reduce(lambda d1, d2: d1.update(d2) or d1, list_of_ds, {})
每次迭代都进行覆盖:{'a': [92], 'b': [65], 'c': [43]}
我尝试过
d_of_ds = {k: v for d in list_of_ds for k, v in d.items()}
覆盖每次迭代:{'a': [92], 'b': [65], 'c': [43]}