I have a list of dicts in python 2.7.
a =[{\'id\': 1,\'desc\': \'smth\'}, {\'id\': 2,\'desc\': \'smthelse\'}, {\'id\': 1,\'desc\': \'smthelse2\'},
You can try:
import operator, itertools key = operator.itemgetter('id') b = [{'id': x, 'desc': [d['desc'] for d in y]} for x, y in itertools.groupby(sorted(a, key=key), key=key)]