I'm trying to update a specific item in a list of dictionaries based on another value
I have the list of dictionaries
Product_id= [{ "id": 342, "count": 10 },
{"id": 345, "count": 20 },
{"id": 546, "count": 30 },
{"id": 324, "count": 40 },
{"id": 789, "count": 50 },
{"id": 675, "count": 60 }]
I'd like to increase the "count" of x "id" where "id" == x
For example if "id" == 342 I want to increase the count by 1 so output would be
print(Product_id)
[{ "id": 342, "count": 11 },
{ "id": 345, "count": 20 },
{ "id": 546, "count": 30 },
{"id": 324, "count": 40 },
{"id": 789, "count": 50 },
{"id": 675, "count": 60 }]
I can bring up the counts but can update() the count...
I've already tried many things and searching stacks etc (and I know my last attempt was way off, below) so any ideas would be welcome
for d in Product_id:
d.update((k + 1, "count") for k, v in d.items() if v\["id"\] == 342)