Best way to find unique items in a list
Thomas Hamelryck
thamelry at vub.ac.be
Thu Feb 24 08:47:09 EST 2000
maxm <maxm at normik.dk> wrote:
: I have written the following snippet to return a list of unique items in
: another list. I just wondered if there was a smarter/faster way of doing it?
You could transform the list into a kjbuckets Set object:
set=kjSet(list)
This will only retain the unique items in the list. If you
want a list again you can do:
unique_list=set.items()
kjSet is part of the kjbuckets module (written in C), so
you'll have to install it separately (which might be overkill
if you're only interested in a simple solution). However, if
you're going to need this often and for large lists it's
probably an excellent solution.
Cheers,
---
Thomas Hamelryck Institute of Molecular and Structural Biology
Aarhus University Gustav Wieds Vej 10C
DK-8000 Aarhus C Denmark
More information about the Python-list
mailing list