Removing duplicates from a list
Thomas Guettler
niemand.leermann at thomas-guettler.de
Wed Sep 14 07:56:55 EDT 2005
Am Wed, 14 Sep 2005 04:38:35 -0700 schrieb Rubinho:
> I've a list with duplicate members and I need to make each entry
> unique.
>
> I've come up with two ways of doing it and I'd like some input on what
> would be considered more pythonic (or at least best practice).
> mylist = set(mylist)
> mylist = list(mylist)
>
> Converting to a set drops all the duplicates and converting back to a
> list, well, gets it back to a list which is what I want.
>
> I can't imagine one being much faster than the other except in the case
> of a huge list and mine's going to typically have less than 1000
> elements.
>
> What do you think?
Hi,
I would use "set":
mylist=list(set(mylist))
Thomas
--
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: niemand.leermann at thomas-guettler.de
More information about the Python-list
mailing list