列表去重

#列表去重
#方法1:
l = [1,2,5,2,2,6,5,6,6,1,2,8]
print(l)

#方法1:
l = [1,2,5,2,2,6,5,6,6,1,2,8]
l_new=[]

for i in l:
    if i not in l_new:
        l_new.append(i)
print('l_new',l_new,n)

#方法2:

l = [1,2,5,2,2,6,5,6,6,1,2,8]
s=set(l)
print('s:',s)

#方法3:
l = [1,2,5,2,2,6,5,6,6,1,2,8]
d=dict.fromkeys(l)

print('d:',list(d.keys()))

#方法4:

import copy
ll=copy.deepcopy(l)

for i in ll:
    #print('i:',i)
    if l.count(i)>1:
        l.remove(i)
        #print('l:',l)

print('l5:',l)

 

 

posted @ 2018-12-29 12:37  小金儿  阅读(152)  评论(0编辑  收藏  举报