0

If I have a list like this: lst = ['a','a','b','a', 'a', 'c', 'c', 'c','d','e','a', 'b', 'b', 'b'],

when I am apply set(lst), it will remove all the duplicates. But I only wanna remove the consistently duplicates and keep the rest of then in order, so my ideal output is ['a', 'b','a', 'c', 'd', 'e', 'a', 'b']

Any help would be really appreciated!

Ali
  • 113
  • 4

1 Answers1

2
from itertools import groupby

lst = ['a','a','b','a', 'a', 'c', 'c', 'c','d','e','a', 'b', 'b', 'b']

print([key for key, _ in groupby(lst)])
Paul M.
  • 10,481
  • 2
  • 9
  • 15