如何对列表去重

用集合的天然去重

list1=[11,22,33,44,33,22]
list2=list(set(list1))
print(list2)
#[33, 11, 44, 22]

用字典的key

a=[12,3,3,3,44,44,22]
d={}
b=d.fromkeys(a)
c=list(b.keys())
print(c)
#[12, 3, 44, 22]

 

posted @ 2018-12-04 11:23  Operater  阅读(445)  评论(0编辑  收藏  举报