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']
日行一善, 日写一撰