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

2008-02-11 Thread thebjorn
On Feb 11, 10:47 am, [EMAIL PROTECTED] wrote: [...] A little known thing from Python 2.5: [...] sorted(lst, key=itemgetter(2, 1)) Cute, thanks :-) --bjorn -- http://mail.python.org/mailman/listinfo/python-list

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

2008-02-11 Thread bearophileHUGS
[repost] Duncan Booth: from operator import itemgetter lst = [(1,2,4),(3,2,1),(2,2,2),(2,1,4),(2,4,1)] lst.sort(key=itemgetter(1)) lst.sort(key=itemgetter(2)) lst [(3, 2, 1), (2, 4, 1), (2, 2, 2), (2, 1, 4), (1, 2, 4)] A little known thing from Python 2.5: from operator import

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

2008-02-10 Thread neocortex
Hello! Thank you all, so much! Now I can do double-criteria sort in at least three ways. More than I have expected. Best, PM -- http://mail.python.org/mailman/listinfo/python-list

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

2008-02-09 Thread neocortex
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:

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

2008-02-09 Thread Jeff Schwab
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

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

2008-02-09 Thread Steve Holden
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

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

2008-02-09 Thread Steven D'Aprano
On Sat, 09 Feb 2008 18:05:14 -0800, 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

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

2008-02-09 Thread thebjorn
On Feb 10, 3:05 am, neocortex [EMAIL PROTECTED] 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

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

2008-02-09 Thread Duncan Booth
thebjorn [EMAIL PROTECTED] wrote: I'm not sure which Python is default for Ubuntu 6.06, but assuming you can access a recent one (2.4), the list.sort() function takes a key argument (that seems to be rather sparsely documented in the tutorial and the docstring...). E.g.: lst =