Is there an easy way to sort a list by two criteria?

Steve Holden steve at holdenweb.com
Sat Feb 9 22:05:33 EST 2008


neocortex wrote:
> Hello!
> I am a newbie in Python. Recently, I get stuck with the problem of
> sorting by two criteria. In brief, I have a two-dimensional list (for
> a table or a matrix). Now, I need to sort by two columns, but I cannot
> figure out how to do that. I read somewhere that it is possible to do:
>>>> table.sort().sort()
> but it does not work.
> Can anyone help me with this?
> PS: I am using Python under Ubuntu 6.06.
> 
I think your best bet would be to google for "decorate sort undecorate" 
  or "Schwartzian transform" unless the columns happen to be in the 
right order in the rows you want to sort.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list