Python-删除列表中重复元素的方法
1.set()方法
x = [1,2,3,4,5,1]
y = list(set(x))
print(y)
```
[1, 2, 3, 4, 5]
```
2.
x = ['b','c','d','b','c','a','a']
y = {}.fromkeys(x).keys()
print(y)
```
dict_keys(['b', 'c', 'd', 'a'])
```
3. set() 方法会改变列表顺序
z = list(set(x))
print(z)
```
['d', 'a', 'c', 'b']
```
4. 使用sort(),使之与原来的相同
z.sort(key=x.index)
z
```
['b', 'c', 'd', 'a']
```
5.
l = []
for i in x:
if not i in l:
l.append(i)
print(l)
```
['b', 'c', 'd', 'a']