方法一:通过集合进行转换,该方式将导致链表无序。
l = [3, 4, 3, 2, 4]
x = list(set(l)) # [2, 3, 4]
方法二:循环提取(保证顺序)
l = [3, 4, 3, 2, 4]
x = []
for item in l:
if item not in l:
x.append(item)
方法三:推导式(保证顺序)
l = [3, 4, 3, 2, 4]
x = []
[x.append(item) for item in l if item not in x]
print x
方法四:通过集合转,再通过sort进行排序
l = [3, 4, 3, 2, 4]
x = sorted(list(set(l)), key=l.index)