码迷,mamicode.com
首页 > 编程语言 > 详细

python中对列表去重复

时间:2021-01-05 10:42:44      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:重复   test   pre   font   append   去重复   bsp   sorted   code   

 

1、

>>> 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]

 

2、

>>> test1 = ["aaa","bbb","aaa","aaa","ccc","ccc","ddd","eee"]
>>> set(test1)
{bbb, aaa, ccc, eee, ddd}
>>> sorted(set(test1))
[aaa, bbb, ccc, ddd, eee]

 

python中对列表去重复

标签:重复   test   pre   font   append   去重复   bsp   sorted   code   

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14219010.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!