文章转载,原博主总结的非常好
出处:http://www.peterbe.com/plog/uniqifiers-benchmark/
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 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