我正在通过循环来匹配两个sperate键的两个dicts的值 - 希望if i in line_aum['id_class'] == line_investor['id_class']
成为True
,然后下一个总和将起作用:
它会产生不同的结果
到目前为止,我有:for line_aum in aum_obj:
for line_investor in investor_obj:
if i in line_aum['id_class'] == line_investor['id_class']:
total = (sum,line_investor['amount'], line_aum['value'])
amount = line['id_class']
print(amount,total)
示例数据:
{'fund_name': '', 'fund_code': 'LFE', 'aumc': '406.37', 'value': '500', 'ddate': '2013-01-01', 'id_fund': '165', 'currency': 'EUR', 'nav': '24.02', 'shares': '16.918', 'estimate': '0', 'id_class': '4526', 'class_name': 'LTD - CLASS B (EUR)'}
答案 0 :(得分:2)
如果itertools.product
和aum_obj
都是列表,请使用investor_obj
代替嵌套循环:
from itertools import product
for line_aum, line_investor in product(aum_obj, investor_obj):
if line_aum['id_class'] == line_investor['id_class']:
# `line_aum` and `line_investor` have matching values for the `id_class` keys.