更新时间:2023-11-28 23:21:04
您可以执行以下操作:
def convert(a):
d = {}
for x in a:
for key,val in x.items():
if key not in d:
d[key] = []
d[key] += val
return d
上面的代码适用于Python 3.
Code above is for Python 3.
如果您使用的是python 2.7,那么我认为您应该将items
替换为iteritems
.
If you're on Python 2.7, then I believe that you should replace items
with iteritems
.