delete duplicates in list
christof hoeke
csad7 at yahoo.com
Wed Oct 29 16:02:08 EST 2003
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
>>> a = [1, 2, 2, 3]
>>> d = {}.fromkeys(a)
>>> b = d.keys()
>>> print b
[1, 2, 3]
there should be an easier or more intuitive solution, maybe with a list
comprehension=
somthing like
>>> b = [x for x in a if x not in b]
>>> print b
[]
does not work though.
thanks for any help
chris
More information about the Python-list
mailing list