sorting list of complex numbers

skip at pobox.com skip at pobox.com
Sun Nov 9 21:49:29 EST 2008


    >> Timeit suggests the single sort returning the real, imag tuples is
    >> faster than two sorts each on one field, as you might expect since
    >> many fewer calls to the key function are made.

    Steve> Only half the number, of course. The advantage of the key
    Steve> function is that each element requires only one call out to a
    Steve> Python function, and the comparisons then take place using a
    Steve> C-coded comparison function.

    Steve> But you knew that already, right?

I knew about the C comparison function, not about the number of key calls.
I sort of assumed the key function was called whenever necessary since it
could have side effects.  I confirmed that the key function is called once
per element instead of once per comparison.

Thanks,

Skip




More information about the Python-list mailing list