sorted unique elements from a list; using 2.3 features

Just just at xs4all.nl
Mon Jan 6 09:41:13 CET 2003


In article <mailman.1041832210.3104.python-list at python.org>,
 "Delaney, Timothy" <tdelaney at avaya.com> wrote:

> > The other is with the new 'fromkeys' class, which constructs
> 
> Actually, dictionary class (static?) method.

It's a class method.

> > # Let 'data' be a list or iterable object
> > subset = dict.fromkeys(data).keys()
> > subset.sort()
> > # Use 'subset' as needed
> 
> This, whilst slightly shorter (due to no import - which in future versions
> will be going away anyway), is definitely *not* the Right Way (TM) to do it.
> It is likely to confuse people.

I don't know. It's currently (apparently) a lot faster than using the 
sets module. With the fromkeys() addition dicts are quite comfortable as 
poor-man's sets.

Just




More information about the Python-list mailing list