python 使用set对列表去重后,保持原来列表的顺序排列

testlist = ['cc', 'bbbb', 'afa', 'sss', 'bbbb', 'cc', 'shafa']
set2list = list(set(testlist))
print set2list
set2list.sort(key = testlist.index) 
print set2list    

运行结果:

['cc', 'shafa', 'bbbb', 'afa', 'sss']
['cc', 'bbbb', 'afa', 'sss', 'shafa']

 

posted @ 2018-12-05 16:15  蒋励  阅读(5160)  评论(0编辑  收藏  举报