More rants on a bad sort

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue Apr 29 04:18:03 EDT 2003


Lulu of the Lotus-Eaters <mertz at gnosis.cx> wrote in 
news:mailman.1051547264.16548.python-list at python.org:

> Given all that, is it POSSIBLE to construct a list containing a string,
> int, and complex, that will not crash on a sort?  I don't know!  I
> couldn't find one--and I THINK the relative order of complex and strings
> precludes it... but actually proving this one way or another is
> decidedly non-obvious.

Given a, b, and c, if a < b < c then the sorting may assume that a < c. In 
the case with unicode and str comparisons you can have a < b < c but a and 
c cannot be compared. To do the same with str, int, complex values you 
would have to have the uncompareable values as a and c, but as was 
mentioned elsewhere in this thread, the numeric types are all fudged to 
have the same ordering against other types, so you can never have an 
ordering a < b < c where b is not a numeric type and a and c both are.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list