I have a python list where elements can repeat.
>>> a = [1,2,2,3,3,4,5,6]
I want to get the first n unique elements from
n
You can use OrderedDict or, since Python 3.7, an ordinary dict, since they are implemented to preserve the insertion order. Note that this won't work with sets.
OrderedDict
dict
N = 3 a = [1, 2, 2, 3, 3, 3, 4] d = {x: True for x in a} list(d.keys())[:N]