python中对列表去重复
2021-06-11 22:03
标签:重复 test pre font append 去重复 bsp sorted code 1、 2、 python中对列表去重复 标签:重复 test pre font append 去重复 bsp sorted code 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14219010.html>>> test1 = ["aaa","bbb","aaa","aaa","ccc","ccc","ddd","eee"]
>>> test2 = []
>>> for i in test1:
if i not in test2:
test2.append(i)
>>> test2
[‘aaa‘, ‘bbb‘, ‘ccc‘, ‘ddd‘, ‘eee‘]
>>> test1 = ["aaa","bbb","aaa","aaa","ccc","ccc","ddd","eee"]
>>> set(test1)
{‘bbb‘, ‘aaa‘, ‘ccc‘, ‘eee‘, ‘ddd‘}
>>> sorted(set(test1))
[‘aaa‘, ‘bbb‘, ‘ccc‘, ‘ddd‘, ‘eee‘]