3 ms·
This does the trick in a (for me) not confusing way: from collections import Counter response = [ { "thing": "A", "cou
by runekaagaard 5y ago
This does the trick in a (for me) not confusing way:
from collections import Counter
response = [
{
"thing": "A",
"count": 4,
},
{
"thing": "B",
"count": 2,
},
{
"thing": "A",
"count": 6,
},
]
counter = Counter()
for x in response:
counter[x["thing"]] += x["count"]
newlist = [{"thing": k, "count": v} for k, v in
counter.items()]
print(newlist)