python方法实现去除列表中重复的元素

#利用集合,直接将列表转化为集合,自动去重后转回列表。有一个问题,转换为集合的同时,数据无序了。
# li = [11,22,22,33,44,44]
# set = set(li)
# li = list(set)
# print(li)
#
#
# 第二种运用新建字典的方式,去除重复的键
# list = [11,22,33,22,44,33]
# dic = {}
# list = dic.fromkeys(list).keys()#字典在创建新的字典时,有重复key则覆盖
# print(list)


#第三种是用列表的推导式
list = [11,22,33,22,44,33]
lis = []        #创建一个新列表
[lis.append  for i in list if not i  in lis]          #循环list里的每一个元素
print(lis)


#第四种仅仅只是将for循环变为while循环
# list = [11,22,33,22,44,33]
# result_list=[]
# temp_list=list
# i=0
# while i<len(temp_list):
# if temp_list[i] not in result_list:
# result_list.append(temp_list[i])
# else:
# i+=1
# print(result_list)

原文地址:https://www.cnblogs.com/wangye666/p/9991313.html