ar=[10,20,20,10,10,30,50,10,20]
ar.sort()
nar = list(set(ar))
the result gives me
nar = [10,20,50,30] instead of [10,20,30,50]
could someone explain this
ar=[10,20,20,10,10,30,50,10,20]
ar.sort()
nar = list(set(ar))
the result gives me
nar = [10,20,50,30] instead of [10,20,30,50]
could someone explain this
Sets do not preserve order by definition.
>>> from collections import OrderedDict
>>> items = [10, 4, 10, 2, 2, 2, 7]
>>> list(OrderedDict.fromkeys(items))
[10, 4, 2, 7]
I really hope this helps!