list conversion question
aleaxit at yahoo.com
Sun Sep 5 18:41:02 CEST 2004
Andrew Dalke <adalke at mindspring.com> wrote:
> In Python2.4 this is allowed
> >>> hist = [ 0, 1, 0, 5, 43 ]
> >>> [pair for pair in sorted(enumerate(hist),
> ... key=lambda pair: pair)]
> [0, 2, 1, 3, 4]
> Not yet sure that that's a good thing.
it makes the fast (DSU) way of sorting easier, and can be sped up
[ p for p in sorted(enumerate(hist), operator.itemgetter(1)) ]
The new itemgetter and attrgetter HOFs in module operator are quite good
for this kind of use (which is exactly why they got introduced).
More information about the Python-list