sort by last then by first

Andrew Dalke adalke at mindspring.com
Tue Jan 28 08:22:49 EST 2003


Padraig at Linux.ie wrote:
> wouldn't it be cool if [].sort() took an optional parameter that
> was essentially the --key option in gnu sort. in this e.g:
> 
> names.sort("--key=1,1 --key=0,0")
> 
> or for more complicated forward and then reverse sorting like you
> suggested:
> 
> names.sort("--key=1,1r --key=0,0")

No, it would not.

1) requires dispatch based on type (string vs. function)

2) would be just about the only function where the argument
parameters are serialized into a string.  (Are there others
in the standard library?)

3) non-obvious (to me at least) on what the different args mean
(eg, why "--key=1,1" instead of "--key=1"?  I'm guessing it's
because the key is start/end column, in which case it disagrees
with Python syntax of start/end+1 column, as in "--key=1,2
--key=0,1".  Then again, why have the '--key' term, expressing
it perhaps as "1r,0" or even support range values as "(1,3),5,4"
or "(1,3),(5,3)" which sorts on rows 1, 2, 5, 4.  And is 1 the
first column or the second?)

4) More generic to have a parse function which turns such a
string into a comparison function, so you have

names.sort(GnuSortOpt("--key=1,1 --key=0,0"))

5) Doesn't handle the more common case of sorting by
attribute name.

					Andrew
					dalke at dalkescientific.com





More information about the Python-list mailing list