from itertools import groupby from operator import itemgetter d = [{\'k\': \'v1\'}] r = ((k, v) for k, v in groupby(d, key=i