Open coder1688 opened 6 years ago
用字典并保持顺序
l1 = ['b','c','d','b','c','a','a'] l2 = list(set(l1)) //应改成 l2={}.fromkeys(l1).keys() l2.sort(key=l1.index) print l2
>>> l1=['b','c','d','c','a','a'] >>> l2=list(set(l1)) >>> l2.sort(key=l1.index) >>> print(l2) ['b', 'c', 'd', 'a']
我在python3上运行没有问题
用字典并保持顺序
l1 = ['b','c','d','b','c','a','a'] l2 = list(set(l1)) //应改成 l2={}.fromkeys(l1).keys() l2.sort(key=l1.index) print l2