hello,
this must have come up before, so i am already sorry for asking but a
quick googling did not give me any answer.
i have a list from which i want a simpler list without the duplicates
an easy but somehow contrived solution would be
[color=blue][color=green][color=darkred]
>>> a = [1, 2, 2, 3]
>>> d = {}.fromkeys(a)
>>> b = d.keys()
>>> print b[/color][/color][/color]
[1, 2, 3]
there should be an easier or more intuitive solution, maybe with a list
comprehension=
somthing like
[color=blue][color=green][color=darkred]
>>> b = [x for x in a if x not in b]
>>> print b[/color][/color][/color]
[]
does not work though.
thanks for any help
chris
this must have come up before, so i am already sorry for asking but a
quick googling did not give me any answer.
i have a list from which i want a simpler list without the duplicates
an easy but somehow contrived solution would be
[color=blue][color=green][color=darkred]
>>> a = [1, 2, 2, 3]
>>> d = {}.fromkeys(a)
>>> b = d.keys()
>>> print b[/color][/color][/color]
[1, 2, 3]
there should be an easier or more intuitive solution, maybe with a list
comprehension=
somthing like
[color=blue][color=green][color=darkred]
>>> b = [x for x in a if x not in b]
>>> print b[/color][/color][/color]
[]
does not work though.
thanks for any help
chris
Comment