Eliminating duplicates entries from a list efficiently

Scott David Daniels Scott.Daniels at Acm.Org
Wed Jul 7 00:05:41 EDT 2004


Larry Bates wrote:

> Take a look at recipe here:...
>>On 3 Jul 2004 00:40:00 GMT, Paul <paul at oz.net> wrote:
>>>Can anyone suggest an efficient way to eliminate duplicate entries
>>>in a list?  The naive approach below works fine, but is very slow

Or even (you get to the first few earlier):

def uniq(lst):
     matched = {}
     for item in lst:
         if item not in matched:
             yield item
             matched[item] = item

-- 
-Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list