#!/usr/local/bin/python2 from collections import OrderedDict class C(object): def __init__(self, v=0): self.name = v l = [C(), C(1), C(2), C(3), C(4), C(5), C(6), C(7), C(8), C(9)] for i in xrange(100000): m = {j.name: j for j in l} n = [j.name for j in l] n = sorted(set(n), key=n.index) c = [j for j in l] c.sort(key=l.index) print m, n, c