DEV Community

Nilotpal Choudhury
Nilotpal Choudhury

Posted on

Answer: How to get only distinct values from a list? [duplicate]

This is what you needed with set():

>>> lst1 = ['A','A','A','B','C','C','D','D','D','B','B']
>>> list(set(lst1))
['A', 'B', 'D', 'C']

Another solution OrderedDict to keep the order of keys during insertion.

>>> from collections import OrderedDict
>>> list(OrderedDict.fromkeys(lst1))
['A', 'B', 'C', 'D']

In case you have liberty to use pandas then try

Top comments (0)