【发布时间】:2020-08-05 09:28:01
【问题描述】:
我怎样才能打开这样的字典列表
dico = [{'a':1}, {'b':2}, {'c':1}, {'d':2}, {'e':2}, {'d':3}, {'g':1}, {'h':4}, {'h':2}, {'f':6}, {'a':2}, {'b':2}]
像这样进入单个字典
{'a':3, 'b':4, 'c':1, 'd':5,'e':2,'f':6 , 'g':1 ,'h':6}
此时此刻
result = {}
for d in dico:
result.update(d)
print(result)
结果:
{'a': 2, 'b': 2, 'c': 1, 'd': 3, 'e': 2, 'g': 1, 'h': 2, 'f': 6}
【问题讨论】:
标签: python list dictionary merge