Removing duplicates from a list
robin.cull at gmail.com
Wed Sep 14 13:38:35 CEST 2005
I've a list with duplicate members and I need to make each entry
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).
Method 1 (the traditional approach)
for x in mylist:
if mylist.count(x) > 1:
Method 2 (not so traditional)
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
What do you think?
More information about the Python-list