#列表去重
#把一个列表重复元素去重;重复元素只保留一个;
#方法1:
l = [1,2,3,2,2,4,4,5,9,20]
for value in l:
num_count=l.count(value)
if num_count>1:
for i in range(num_count-1):
l.remove(value)
print(l)
#封装成函数
def rm_duplic(l):
for value in l:
count=l.count(value)
if count>1:
for i in range(cout-1):
l.remove(value)
return l
#方法2:
def rm_duplic(l):
new_list=[]
for value in l:
if value in new_list:
continue
else:
new_list.append(value)
return new_list