如何将单个变量中的这些不同字典连接到一个字典中
How do I join these different dictionary in a single variable to one single dictionary
转换函数:
def Convert(a):
it = iter(a)
res_dct = dict(zip(it, it))
return res_dct
w=0
r=0
u={}
for q in lit:
w=(list(q))
r=Convert(w)
for key, value in r.items():
r[key] = value
print(r)
输出:
{'chapter': 56} {'i': 2597} {'emma': 719} {'woodhouse': 249} {'handsome': 30}
{'clever': 24} {'and': 4534} {'rich': 14} {'with': 1244} {'a': 3101}
{'comfortable': 34} {'home': 112} {'happy': 116} {'disposition': 23}
{'seemed': 139} {'to': 5202} {'unite': 3} {'some': 260} {'of': 4363}
{'the': 5271}
我需要在单个字典中输出这些内容
最初 lit 是一个包含输出列表的列表
lit = [{'chapter': 56},
{'i': 2597},
{'emma': 719},
{'woodhouse': 249} ,
{'handsome': 30},
{'clever': 24} ,
{'and': 4534},
{'rich': 14} ,
{'with': 1244} ,
{'a': 3101} ,
{'comfortable': 34},
{'home': 112},
{'happy': 116},
{'disposition': 23} ,
{'seemed': 139} ,
{'to': 5202},
{'unite': 3},
{'some': 260},
{'of': 4363} ,
{'the': 5271}]
res = {}
for i in lit:
for k in i:
res[k] = i[k]
print(res)
转换函数:
def Convert(a):
it = iter(a)
res_dct = dict(zip(it, it))
return res_dct
w=0
r=0
u={}
for q in lit:
w=(list(q))
r=Convert(w)
for key, value in r.items():
r[key] = value
print(r)
输出:
{'chapter': 56} {'i': 2597} {'emma': 719} {'woodhouse': 249} {'handsome': 30}
{'clever': 24} {'and': 4534} {'rich': 14} {'with': 1244} {'a': 3101}
{'comfortable': 34} {'home': 112} {'happy': 116} {'disposition': 23}
{'seemed': 139} {'to': 5202} {'unite': 3} {'some': 260} {'of': 4363}
{'the': 5271}
我需要在单个字典中输出这些内容
最初 lit 是一个包含输出列表的列表
lit = [{'chapter': 56},
{'i': 2597},
{'emma': 719},
{'woodhouse': 249} ,
{'handsome': 30},
{'clever': 24} ,
{'and': 4534},
{'rich': 14} ,
{'with': 1244} ,
{'a': 3101} ,
{'comfortable': 34},
{'home': 112},
{'happy': 116},
{'disposition': 23} ,
{'seemed': 139} ,
{'to': 5202},
{'unite': 3},
{'some': 260},
{'of': 4363} ,
{'the': 5271}]
res = {}
for i in lit:
for k in i:
res[k] = i[k]
print(res)