在itertools有个强大的函数groupby可以很快捷的实现: a = [1, 4, 5, 4, 9, 1, 2, 3, 4, 5, 11] a.sort() b = [k for k, g in groupby(a)] print b