list1 = ['b','c','d','b','c','a','a']
list2 = list(set(list1))
print list2
list1 = ['b','c','d','b','c','a','a']
list2 = {}.fromkeys(list1).keys()
print list2
但是通过这两种方法获得的list2排序变了,如果想维持原来list的排序可以通过以下方法:
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 not i in l2:
l2.append(i)
print l2
l1 = ['b','c','d','b','c','a','a']
l2 = []
[l2.append(i) for i in l1 if not i in l2]
print l2