This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients LeWiemann, gvanrossum, mark.dickinson, rhettinger, tixxit
Date 2009-12-06.11:57:28
SpamBayes Score 3.1684955e-10
Marked as misclassified No
Message-id <1260100651.05.0.868730760351.issue1771@psf.upfronthosting.co.za>
In-reply-to
Content
Tom, I think I'm missing your point:  all three of the examples you give 
seem like perfect candidates for a key-based sort rather than a 
comparison-based one.  For the first example, couldn't you do something 
like:

def direction(pt1, pt2):
    """angle of line segment from point 1 to point 2"""
    return atan2(pt2.y - pt1.y, pt2.x - pt1.x)

my_points.sort(key=lambda pt: direction(reference_pt, pt))

? How would having a cmp keyword argument make this any easier or 
simpler?


Here's the best example I can think of for which key-based sorting is 
problematic:  imagine that the Decimal type doesn't exist, and that you 
have triples (sign, coefficient_string, exponent) representing 
arbitrary-precision base 10 floating-point numbers.  It's fairly tricky 
to come up with a key function that maps these triples to some existing 
ordered type, so that they can be sorted in natural numerical order.  
The problem lies in the way that the sort order for the coefficient 
string and exponent depends on the value of the sign (one way for 
positive numbers, reversed for negative numbers). But it's not a big 
deal to define a wrapper for cases like this.
History
Date User Action Args
2009-12-06 11:57:31mark.dickinsonsetrecipients: + mark.dickinson, gvanrossum, rhettinger, LeWiemann, tixxit
2009-12-06 11:57:31mark.dickinsonsetmessageid: <1260100651.05.0.868730760351.issue1771@psf.upfronthosting.co.za>
2009-12-06 11:57:29mark.dickinsonlinkissue1771 messages
2009-12-06 11:57:28mark.dickinsoncreate