码迷,mamicode.com
首页 > 其他好文 > 详细

list去重的四种方式

时间:2019-09-11 10:11:30      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:lis   方式   ict   while   四种   ret   rem   count   bsp   


L=[1,2,3,3,5,5,5,8,4,6,9,7,2,‘a‘,‘s‘,‘a‘,‘e‘,‘s‘,‘z‘]

def DelDupli(L):
    L1=[]
    for i in L:
        if i not in L1:
            L1.append(i)
    return L1

def DelDupli2(L):
    return list(set(L))

def DelDupli3(L):
    dict={}
    for i in L:
        dict[i] = 0
    L=list(dict.keys())
    return L

def DelDupli4(L):
    for i in L:
        while L.count(i)>1:
            L.remove(i)
    return L
print(DelDupli(L))
print(DelDupli2(L))  
print(DelDupli3(L))  
print(DelDupli4(L))      
----->
[1, 2, 3, 5, 8, 4, 6, 9, 7, ‘a‘, ‘s‘, ‘e‘, ‘z‘]
[‘a‘, 1, 2, 3, 4, 5, 6, 7, 8, 9, ‘s‘, ‘e‘, ‘z‘]
[‘a‘, 1, 2, 3, 4, 5, 6, 7, 8, 9, ‘s‘, ‘e‘, ‘z‘]
[1, 3, 5, 8, 4, 6, 9, 7, 2, ‘a‘, ‘e‘, ‘s‘, ‘z‘]

list去重的四种方式

标签:lis   方式   ict   while   四种   ret   rem   count   bsp   

原文地址:https://www.cnblogs.com/qxh-beijing2016/p/11504267.html

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