方法1:是利用map的fromkeys来自过滤重复制,map是基于hash的,大数组的时候应该会比排序快点
方法2:是用set(),set是定义集合的,无序,非重复
方法3:是排序后,倒着扫描,遇到已有的元素删之
方法1:
def dlist():
a = [1,2,2,3,4,5,5,6,7,6]
b = {}
b = fromkeys(a) # {1: None, 2: None, 3: None, 4: None, 5: None, 6: None} key基于hash值去重
print(b)
a = list(b.keys())
print(a)
方法2:
def dlist():
a = [1,2,2,3,4,5,5,6,7,6]
a = list(set(a))# set是非重复的,无序集合,可以用list来排序,list()转换成列表,a.sort来排序
print(a)
方法3:
def dlist():
b = list()
a = [1,2,2,3,4,5,5,6,7,6]
for i in a:
if i not in b:
b.append(i)
return b