sorting list of complex numbers
Thomas Bellman
bellman at lysator.liu.se
Tue Nov 11 13:57:20 EST 2008
Steve Holden <steve at holdenweb.com> wrote:
> Only half the number, of course. The advantage of the key function is
> that each element requires only one call out to a Python function, and
> the comparisons then take place using a C-coded comparison function.
You don't need any Python-coded function at all. The operator
module is your friend: key=operator.attrgetter('real', 'imag')
will create the required tuples for sorting.
--
Thomas Bellman, Lysator Computer Club, Linköping University, Sweden
"God is real, but Jesus is an integer." ! bellman @ lysator.liu.se
! Make Love -- Nicht Wahr!
More information about the Python-list
mailing list