def test1():
lst = [1,2,5,6,3,5,7,3]
tmp = []
for it in lst:
if it not in tmp:
tmp.append(it)
print(tmp)
结果:
[1, 2, 5, 6, 3, 7]
def test2():
lst = [1,2,5,6,3,5,7,3]
tmp = list(set(lst))
print(tmp) # 顺序改变
tmp.sort(key=lst.index)
print(tmp) # 顺序不变
结果:
[1, 2, 3, 5, 6, 7]
[1, 2, 5, 6, 3, 7]