Message from Python discussions

November 2018

— Hi everyone

— 

How I can get from this list

a = [{'name': 'a', 'sum': 1}, {'name': 'a', 'sum': 2}, {'name': 'b', 'sum': 2}]
this one
b = [{'name': 'a', 'sum': 3}, {'name': 'b', 'sum': 2}]

— Now I am doing like that

import collections

x = collections.Counter()
for i in a:
x[i['name']] += i['sum']

b = []
for k, v in x.items():
b.append({'name': k, 'sum': v})

Message permanent page

— And it's work

— But I want refactor my code

— Maybe there are some features of python

— Hello

— Hie

— !offtopic

— Lol a guy asked how to iterate through the lines of a string in python and people suggested to use huge functions,other libs etc when at the same time there is

for line in string.split('\n')

Message permanent page

— Hah. What did they suggest?

— Https://stackoverflow.com/questions/3054604/iterate-over-the-lines-of-a-string