37,719
社区成员
发帖
与我相关
我的任务
分享
dataA_list = [{'id': 1, 'status': 1, 'name': '项目1', 'money': 1111},
{'id': 2, 'status': 1, 'name': '项目2', 'money': 2222},
{'id': 3, 'status': 1, 'name': '项目3', 'money': 3333}]
dataB_list = [{'id': 1, 'status': 2, 'name': '项目1', 'money': 111}, {'id': 2, 'status': 2, 'name': '项目2', 'money': 222},
{'id': 4, 'status': 2, 'name': '项目4', 'money': 4444}]
dataC_list = [{'id': 5, 'status': 3, 'name': '项目5', 'money': 5555}, {'id': 3, 'status': 3, 'name': '项目3', 'money': 33},
{'id': 1, 'status': 3, 'name': '项目1', 'money': 11}]
def the_sum(*params):
result = {}
for the_list in params:
for the_dict in the_list:
if the_dict['id'] not in result:
result[the_dict['id']] = the_dict
del result[the_dict['id']]['status']
else:
result[the_dict['id']]['money'] += the_dict['money']
return [result[key] for key in result]
if __name__ == '__main__':
print(the_sum(dataA_list, dataB_list, dataC_list))