python 将一个列表去重,并且不打乱它原有的排列顺序

old_lst = [2, 2, 1, 1, 3, 4]
new_lst = list(set(old_lst))
new_lst.sort(key=old_lst.index)
print(new_lst)

new_lst1 = []
for i in old_lst:
    if i not in new_lst1:
        new_lst1.append(i)
print(new_lst1)

1 第一种方法利用了集合 

2 第二种方法利用了遍历查找

原文地址:https://www.cnblogs.com/xiaozx/p/10458686.html