My question is similar to this(Python sum on keys for List of Dictionaries), but need to sum up the values based on two or more key-value elements. I have a list of dictionaries as following:
list_to_sum=
[{'Name': 'A', 'City': 'W','amt':100},
{'Name': 'B', 'City': 'A','amt':200},
{'Name': 'A', 'City': 'W','amt':300},
{'Name': 'C', 'City': 'X','amt':400},
{'Name': 'C', 'City': 'X','amt':500},
{'Name': 'A', 'City': 'W','amt':600}]
So based on a combination of Name and City key values, amt should be summed. Please let me know how to solve this.
Output: [{'Name': 'A', 'City': 'W','amt':900},
{'Name': 'B', 'City': 'A','amt':200},
{'Name': 'C', 'City': 'X','amt':900}]