def doit(a): b = [] while len(a) > 0: x = a.pop(0) if not x in b or not x in a: b.append(x) return b [G:/] $ python -i foo.py >>> doit([1,2,3,3,2,1,1,2,3,2,2,3]) [1, 2, 3, 1, 2, 3] >>> doit([0,1,0,3,0,0,0,0,0]) [0, 1, 3, 0] >>>