我试过了
def remove_extra(lst):
return print(sorted(set(lst), key = lst.index))
def remove_extra(lst):
b = []
for x in lst:
if x not in b:
b.append(x)
print(b)
所有类型的删除重复代码但是我不知道那个
在True
result1 is lst1
result1 = remove_extra(lst1)
答案 0 :(得分:1)
data = [1, 2, 3, 4, 4, 2, 1]
def remove_extra(lst):
seen, result = set(), []
for item in lst:
if item not in seen:
result.append(item)
seen.add(item)
lst[:] = result
return lst
print data is remove_extra(data)
# True
print data
[1, 2, 3, 4]