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
[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
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
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:
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
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
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
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
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 =