I have a list like this in Python:
my_list = [
{"id":1,"symbol":"ABC","quantity":100},
{"id":2,"symbol":"PQR","quantity":500},
{"id":3,"symbol":"ABC","quantity":300},
{"id":1,"symbol":"XYZ","quantity":320},
{"id":3,"symbol":"PQR","quantity":800},
]
I wanted to sum up a quantity which have similar symbols and create a new list. The new_list will look like this:
new_list = [
{ "symbol":"ABC","total_quantity":400,"ids":"1 3"}
{ "symbol":"PQR","total_quantity":1300,"ids":"2 3"}
{ "symbol":"XYZ","total_quantity":320,"ids":"1"}
]
I am fairly new to Python and tried some ways but not working. What can I try to achieve this?