1.使用set函数
In [116]: a=[1,2,3,2,1,3,4,5,6,5] In [117]: set(a)
Out[117]: {1, 2, 3, 4, 5, 6}
2.使用字典函数
In [118]: a=[1,2,3,2,1,3,4,5,6,5] In [119]: b={} In [120]: c=b.fromkeys(a) In [121]: c.keys()
Out[121]: dict_keys([1, 2, 3, 4, 5, 6]) In [122]: list(c.keys())
Out[122]: [1, 2, 3, 4, 5, 6]