l1 = ['b','c','d','b','c','a','a']
l2 = list(set(l1))
print(l2)
l1 = ['b','c','d','b','c','a','a']
l2 = {
}.fromkeys(l1).keys()
print(l2)
l1 = ['b','c','d','b','c','a','a']
l2 = list(set(l1))
l2.sort(key=l1.index)
print(l2)
另一种写法:
l1 = ['b','c','d','b','c','a','a']
l2 = sorted(set(l1),key=l1.index)
print(l2)
l1 = ['b','c','d','b','c','a','a']
l2 = []
for i in l1:
if i not in l2:
l2.append(i)
print(l2)
简明写法:
l1 = ['b', 'c', 'd', 'b', 'c', 'a', 'a']
l2 = []
[l2.append(i) for i in l1 if i not in l2]
print(l2)