uniq, was Re: PEP Parade

Hernan M. Foffani hfoffani at yahoo.com
Fri Mar 8 17:37:18 EST 2002


"Roman Suzi"
> On Fri, 8 Mar 2002, Skip Montanaro wrote:
> >Nothing new is necessary since 2.2 was released:
> >
> >    >>> mylist = [1,2,3,5,6,6,9,9,1,2,3,4]
> >    >>> mydict = dict(zip(mylist,mylist))
> >    >>> mydict
> >    {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 9: 9}
> >    >>> mydict.values()
> >    [1, 2, 3, 4, 5, 6, 9]
>
> Wow. Then I am a bit underinformed. What uniq is for then?
> To cover lengthy:
>
> def uniq(x):
>   return dict(map(None, x, [None])).keys()
>
> ?
>

keys in a dictionary have to be inmutable objects. The list
we want to remove duplicates can contain other object type.
See Tim's recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560/index_txt

-Hernan





More information about the Python-list mailing list