Eliminating duplicates entries from a list efficiently

Paul paul at oz.net
Fri Jul 2 20:40:00 EDT 2004


Can anyone suggest an efficient way to eliminate duplicate entries
in a list?  The naive approach below works fine, but is very slow 
with lists containing tens of thousands of entries:

def uniq(list):
    u = []
    for x in list:
        if x not in u: u.append(x)
    return u
    
print uniq(['a','b','c','a'])
['a', 'b', 'c']

Thanks,

-- Paul





More information about the Python-list mailing list