sort by last then by first

Padraig at Linux.ie Padraig at Linux.ie
Tue Jan 28 11:54:23 EST 2003


Andrew Dalke wrote:
> Padraig at Linux.ie wrote:
> 
>> Andrew Dalke wrote:

[snip]

>> Yes you're probably right that gnu sort has too much baggage.
>> How about passing a tuple like: ("1(r)","0(n)")
>> This would first reverse sort on second "column" and
>> then forward sort on first column treating strings as numeric
> 
> Python objects are strongly typed so there it no need to say
> "treating strings as numeric".  The values should be numbers in
> the first place.

I was suggesting this as a way to auto convert data that
was already in string format. For e.g. if importing tabular
data, using split, then you get all string fields. Actually
it would be good if you could pass to split what format the
fields are, something like:

line.split('\t',4,(str,int,float,str))

> If you want an option to do so, you need to
> allow that float and int types have different ranges, eg,

not too sure what you mean, but you're probably right
in that type info shouldn't be passed in.

>>> 5) Doesn't handle the more common case of sorting by
>>> attribute name.
>>
>> ("attr2(r)", "attr1(n)")
> 
> 
> Why not just write this as Python code?

speed

Pádraig.





More information about the Python-list mailing list