0

I have a list and don't know all the values but I want to remove all the values which occurs more than once and only one of that value is left.Suppose here is the list:

lst = ['one', 'two', 'three', 'four','four','five','five','five']

This is what I need:

lst = ['one', 'two', 'three', 'four','five']

Here is what I have tried:

i=0
for ele in lst:
if ele[i] in lst:
    lst.remove(ele[i])

but it's not working.

Sibtain Reza
  • 513
  • 2
  • 14

1 Answers1

2

This works pretty well:

lst = ['one', 'two', 'three', 'four','four','five','five','five']
newList = list(dict.fromkeys(lst))
print(newList)

output: ['one', 'two', 'three', 'four', 'five']

Uber
  • 331
  • 1
  • 5
  • 18