Removing duplicates from a list

Steven Bethard steven.bethard at gmail.com
Wed Sep 14 19:08:01 EDT 2005


przemek drochomirecki wrote:
> def unique(s):
>  e = {}
>  for x in s:
>   if not e.has_key(x):
>    e[x] = 1
>  return e.keys()

This is basically identical in functionality to the code:

     def unique(s):
         return list(set(s))

And with the new-and-improved C implementation of sets coming in Python 
2.5, there's even more of a reason to use them when you can.

STeVe



More information about the Python-list mailing list