delete duplicates in list

Alex Martelli aleax at aleax.it
Wed Oct 29 16:23:21 EST 2003


Diez B. Roggisch wrote:


>> 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
> 
> In python 2.3, this should work:
> 
> import sets
> l = [1,2,2,3]
> s = sets.Set(l)
> 
> A set is a container for which the invariant that no object is in it twice
> holds. So it suits your needs.

...except it's not a LIST, which was part of the specifications given
by the original poster.  It may, of course, be that you've read his
mind correctly and that, despite his words, he doesn't really care
whether he gets a list or a very different container:-).


Alex





More information about the Python-list mailing list