使用in或者not in方法把下面列表中的重复的元素去重并返回结果,并且提取重复的元素返回结果

def no_repeat():
"""去掉重复的元素并返回结果->lis,提取重复的元素返回结果->list_repeat"""
a = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10]
lis = []
list_repeat = []
for i in a:
if i not in lis:
lis.append(i)
print(lis)
for j in lis:
if a.count(j) > 1:
list_repeat.append(j)
print(list_repeat)


no_repeat()
原文地址:https://www.cnblogs.com/laosun0204/p/11127535.html