'''列表去重3种方法''' #定义一个字典,将列表重复的字数作为value值,将列表的元素作为键值,存入字典中 #打印出字典 #将字典的键值转化成列表2,即完成了列表去重 list1=[1,1,2,2,3,3,3,4,4,4,4,5,5,5,5,6,6,6,11,12,12] D1={} count=0 for i in list1: count+=1 D1[i]=count print("D1=",D1) list2=list(D1.keys()) print(list2) ----------------------------------- list2 = list(set(list1)) print(list2) -------------------------------------- list2 = [] for x in list1: if x not in list2: list2.append(x) print(list2)