我想删除没有设置的重复数字。我想使用def函数,还有什么东西吗?
"."
答案 0 :(得分:0)
x =[1,3,4,5,5,5,5,6,8,9]
def removeDuplicates(array):
new = []
for item in array:
if item not in new:
new.append(item)
return new
print(removeDuplicates(x))
答案 1 :(得分:0)
如果订购了清单:
x = [1, 3, 4, 5, 5, 5, 5, 6, 8, 9]
print(x) # [1, 3, 4, 5, 5, 5, 5, 6, 8, 9]
y = [v for i, v in enumerate(x) if x[i-1] != v or i==0]
print(y) # [1, 3, 4, 5, 6, 8, 9]