Use itertools.groupby
itertools.groupby
from itertools import groupby [key for key, _ in groupby(my_list)]
['apple', 'boy', 'cat', 'apple', 'boy', 'cat', 'dog']
2.1m questions
2.1m answers
60 comments
57.0k users