方法1:使用set函数
s=set(list),然后再list(s)
方法2:append
def delList(L):
L1 = []
for i in L:
if i not in L1:
L1.append(i)
return L1 print(delList([1,2,2,3,3,4,5]))
print(delList([1,8,8,3,9,3,3,3,3,3,6,3]))
方法3:count,remove
def delList(L):
for i in L:
if L.count(i) != 1:
for x in range((L.count(i)-1)):
L.remove(i)
return L print(delList([1,2,2,3,3,4,5]))
print(delList([1,8,8,3,9,3,3,3,3,3,6,3]))