我有一个列表,不知道所有的值,但我想删除所有多次出现的值,并且只剩下其中一个值。假设列表如下:
lst = ['one', 'two', 'three', 'four','four','five','five','five']
这就是我需要的:
lst = ['one', 'two', 'three', 'four','five']
以下是我尝试过的:
i=0
for ele in lst:
if ele[i] in lst:
lst.remove(ele[i])
但它不起作用。
这很好用:
lst = ['one', 'two', 'three', 'four','four','five','five','five']
newList = list(dict.fromkeys(lst))
print(newList)
输出:['one', 'two', 'three', 'four', 'five']