I have a list of elements 1,...,K with repeats. For example for K=4 :
[4 2 1 1 2 1 1 3 2 ]
I want to find the sequence that 1,...,K is appeared in the list (without sorting). For example for the above sequence, the result would be
[4, 2 ,1 ,3 ]
How can I write this algorithm efficiently in python, with less runtime.
Thank you!
from collections import OrderedDict
list_numbers=[4,2,1,1,2,1,1,3,2]
print list(OrderedDict.fromkeys(list_numbers))
This gives the desired output - [4, 2, 1, 3]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With