【发布时间】:2019-11-24 21:46:40
【问题描述】:
我有一本字典:
d=[{'court': 4, 'hope': 6},
{'court': 9, 'hope': 27},
{'hope': 5, 'mention': 2, 'life': 10, 'bolster': 1, 'internal': 15, 'level': 1}]
并列出
l=[2, 9, 5]
我只想用相应的字典值来划分列表元素。某事,
new_list=[{'court': 2, 'hope': 3},
{'court': 1, 'hope': 3},
{'hope': 1, 'mention': 0.4, 'life': 2, 'bolster': 0.2, 'internal': 3,'level': 0.2}]
我所做的一切,
new_list=[]
for i in d:
for k,j in i.items():
new={k:j/o for o in l}
new_list.append(new)
它作为包含单个元素的列表返回:
[{'court': 2},{'hope': 3},
{'court': 1},{'hope': 3},
{'hope': 1},{'mention': 0.4},{'life': 2},{'bolster': 0.2},{'internal': 3},{'level': 0.2}]
【问题讨论】:
标签: python arrays python-3.x dictionary