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']
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']
转载于:https://www.cnblogs.com/xiyuan2016/p/10071607.html