Is there an obvious/pythonic way to remove duplicates from a
list (resulting order doesn't matter, or can be sorted
postfacto)? My first-pass hack was something of the form
[color=blue][color=green][color=darkred]
>>> myList = [3,1,4,1,5,9,2,6 ,5,3,5]
>>> uniq = dict([k,None for k in myList).keys()[/color][/color][/color]
or alternatively
[color=blue][color=green][color=darkred]
>>> uniq = list(set(myList ))[/color][/color][/color]
However, it seems like there's a fair bit of overhead
here...creating a dictionary just to extract its keys, or
creating a set, just to convert it back to a list. It feels
like there's something obvious I'm missing here, but I can't
put my finger on it.
Thanks...
-tkc
list (resulting order doesn't matter, or can be sorted
postfacto)? My first-pass hack was something of the form
[color=blue][color=green][color=darkred]
>>> myList = [3,1,4,1,5,9,2,6 ,5,3,5]
>>> uniq = dict([k,None for k in myList).keys()[/color][/color][/color]
or alternatively
[color=blue][color=green][color=darkred]
>>> uniq = list(set(myList ))[/color][/color][/color]
However, it seems like there's a fair bit of overhead
here...creating a dictionary just to extract its keys, or
creating a set, just to convert it back to a list. It feels
like there's something obvious I'm missing here, but I can't
put my finger on it.
Thanks...
-tkc
Comment