I have a list like the following
a = [5,5,5,5,3,3,2,2,2,2,5,5,5,2,2,2,2,2]
I wish to have the following output list
b = [5,3,2,5,2]
Note that I have tried using
list(OrderedDict.fromkeys(a))
which gives me
[5, 3, 2]
Notice that it does not consider the 2nd 5 or the 2nd 2 as they are non-unique by then.
I need a way to make the machine understand that as and when it encounters a unique element (say the first '5'), it should store it in list b. Consequently, when it encounters the first '3' or first '2', it should store them in list b as well. No problems until this point. As it encounters the second set of '5's, it should store that 5 as a new element in list b. Same goes for the second set of 2's.
Is there a Pythonic way to do this?