Sorting Lists
phawkins at connact.com
phawkins at connact.com
Wed Jul 25 12:55:32 EDT 2001
>>>>> "TB" == Tom Bryan <tbryan at python.net> writes:
TB> While it's probably much harder to read, one could
TB> avoid copying the list twice and maintain the semantics
TB> of sorting in place by doing something like the following...
TB> def sort_by_field( index ):
TB> def cmpfunc( x, y, i=index ):
TB> return cmp( x[i], y[i] )
TB> return cmpfunc
TB> data.sort( sort_by_field( 2 ) )
TB> ---Tom
That's what I thought, but when I timed it, I found that this method
is slower, because of the repeat function calls. (Which means I have a
bunch of cmpfnc-style sorts to rewrite using decorate/undecorate...)
Patricia
--
Patricia J. Hawkins
Hawkins Internet Applications, LLC
More information about the Python-list
mailing list