Sorting: too different times. Why?

Dave Angel davea at ieee.org
Sun Nov 22 13:28:43 EST 2009


n00m wrote:
>> The second part of the compound if is backwards.  So if this is headed
>> for production code, it better get fixed.
>>
>> DaveA
>>     
>
> Not sure I'm understanding your remark.
>
>   
Well, others in the thread have observed the same thing, so maybe it 
doesn't matter.  But the quoted code had only one if statement:

 >>def v_cmp(v1, v2):
 >>    if v1.x < v2.x and v1.y > v2.y:
 >>        return -1
 >>    return 0

 
And the first part of the compound if is a "<" comparison, while the 
second part is a ">" comparison

This produces a different sort order than the default tuple comparison.  
So it needs fixing.

DaveA





More information about the Python-list mailing list