get rid of duplicate elements in list without set

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Mar 20 22:37:56 CET 2009


On Fri, 20 Mar 2009 07:16:40 -0700, Alexzive wrote:

> Hello there,
> 
> I'd like to get the same result of set() but getting an indexable
> object.
> How to get this in an efficient way?

Your question is too open-ended. Do you want to keep the items in the 
original order? Are the items hashable? Do they support comparisons?

http://code.activestate.com/recipes/52560/


If all you care is that the result is indexable, then list(set(items)) 
will do what you want -- but beware, sets can only contain hashable 
items, so if your original data contains dicts, lists or other unhashable 
objects, you can't add them to a set.



-- 
Steven



More information about the Python-list mailing list