from collections import OrderedDict o = collections.OrderedDict() for i in data: o.setdefault(i[0], []).append(i[1])