below I have 2 list of dics, I would like to know how I can loop through both lists and find matching environments and ids and add the costs to my formatted\_list where id == id and environment == environment. I only want a prod and non prod pair of id's in my formatted\_list. My current logic is creating multiple id's in my formatted list. How can I just add costs to my formatted\_ist from my results\_ecs list?

```
def main(formatted_results_ecs, formatted_list):
ecs_deduction = 0
for ecs_cost in formatted_results_ecs:
    for cost_est in formatted_list:
        if ecs_cost["id"] == cost_est["id"] and ecs_cost["environment"] == cost_est["environment"]:
            combined_cost = ecs_cost["cost"] + cost_est["cost"]
            cost_est["cost"] = combined_cost
            ecs_deduction += combined_cost

if __name__ == '__main__':
    formatted_results_ecs = [
        {'id': 'ffd07d03-e10b-4d60-8e28-e4ab617bf394', 'cost': 3.2980019999999994, 'environment': 'prod'},
        {'id': 'ffc87314-16e4-4c77-b5ec-f34066458ce4', 'cost': 215.82577600000002, 'environment': 'prod'},
        {'id': 'ff66d353-6644-4c61-9c22-204960d65a18', 'cost': 291.61807799999997, 'environment': 'prod'},
        {'id': 'a855d85f-65e4-40bb-a21f-6ceea77628cc', 'cost': 19.041902000000004, 'environment': 'prod'},
        {'id': 'aa385029-afa6-4f1a-a1d9-d88b7d934699', 'cost': 2.033628000000001, 'environment': 'prod'},
        {'id': 'adf44794-50eb-45db-9323-6ce5fd31699e', 'cost': 1120.8391390000004, 'environment': 'prod'},
        {'id': 'b13a0676-6926-49db-808c-3c968a9278eb', 'cost': 15145.140081999996, 'environment': 'prod'},
        {'id': 'e4c3c7b9-5941-4cf7-aa90-f63a142ccaf4', 'cost': 3319.4728399999995, 'environment': 'prod'},
        {'id': 'ff66d353-6644-4c61-9c22-204960d65a18', 'cost': 6.0234558329471, 'environment': 'nonprod'},
        {'id': 'ff66d353-6644-4c61-9c22-204960d65a18', 'cost': 7.9407999472248, 'environment': 'prod'},
        {'id': '2d1e7f15-d3bb-4649-996e-a7afb55b7637', 'cost': 5.940205, 'environment': 'prod'},
        {'id': '6841509d-1d68-4af3-b04e-8bc7e87d0c89', 'cost': 651.016164, 'environment': 'prod'},
        {'id': 'ffd07d03-e10b-4d60-8e28-e4ab617bf394', 'cost': 3.287444999999999, 'environment': 'nonprod'},
        {'id': 'ffc87314-16e4-4c77-b5ec-f34066458ce4', 'cost': 214.46528800000002, 'environment': 'nonprod'},
        {'id': 'ff66d353-6644-4c61-9c22-204960d65a18', 'cost': 291.55481199999997, 'environment': 'nonprod'},
        {'id': 'aa385029-afa6-4f1a-a1d9-d88b7d934699', 'cost': 2.0193450000000013, 'environment': 'nonprod'},
    ]
    formatted_list = [
        {'id': 'ffd07d03-e10b-4d60-8e28-e4ab617bf394', 'cost': 13.431203414269257, 'environment': 'nonprod'},
        {'id': 'ffc87314-16e4-4c77-b5ec-f34066458ce4', 'cost': 3.1723085934801296, 'environment': 'nonprod'},
        {'id': 'ff66d353-6644-4c61-9c22-204960d65a18', 'cost': 602.0234558329471, 'environment': 'nonprod'},
        {'id': 'ff66d353-6644-4c61-9c22-204960d65a18', 'cost': 607.9407999472248, 'environment': 'prod'},
        {'id': 'ff4f589f-2616-4f5e-9fb0-09e7ab3d200c', 'cost': 0.187242731922548, 'environment': 'prod'},
        {'id': 'ff2041fb-711f-4bca-a336-5c6ac07fb8f3', 'cost': 1.179409983e-06, 'environment': 'nonprod'},
        {'id': 'ff2041fb-711f-4bca-a336-5c6ac07fb8f3', 'cost': 1.179409983e-06, 'environment': 'prod'},
        {'id': 'fba58f4f-303c-4a20-86d3-294714c8db5c', 'cost': 14.494946621907866, 'environment': 'nonprod'},
        {'id': 'f8780ef9-0211-486b-ac2d-1b85d6bcb9da', 'cost': 19.592325435434688, 'environment': 'nonprod'},
        {'id': 'f8780ef9-0211-486b-ac2d-1b85d6bcb9da', 'cost': 19.288246392238705, 'environment': 'prod'},
        {'id': 'f7f16766-1212-4747-9c98-7a37d125e850', 'cost': 0.8798593169569822, 'environment': 'nonprod'},
        {'id': 'f7d59e13-cba1-4a13-af57-8c4aec3ee281', 'cost': 30.22516723291206, 'environment': 'prod'},
        {'id': 'f7d59e13-cba1-4a13-af57-8c4aec3ee281', 'cost': 29.88632221088805, 'environment': 'nonprod'},
        {'id': 'f742f6ea-01dc-4add-a283-6afa6656a87b', 'cost': 18.657917564221908, 'environment': 'prod'}
    ]
    main(formatted_list, formatted_results_ecs)

```

a good example id is ff66d353-6644-4c61-9c22-204960d65a18. This id shows up 4 times in the formatted\_result\_ecs list and im trying to add cost by env to my foratted\_list. Any breakdown or explanation of how this solution should work would be greatly appreciated.