On Mon, May 25, 2009 at 12:51 AM, Jaime Fernandez del Rio <jaime.f...@gmail.com> wrote: > Hi Dhananjay, > > Sort has several optional arguments, the function's signature is as follows: > > s.sort([cmp[, key[, reverse]]]) > > If you store your data as a list of lists, to sort by the third column > you could do something like: > > data.sort(None, lambda x : x[2]) > > For more complex sortings, as the one you propose, you need to define > a compare function, that determines if an object preceeds another or > not. In your case, something like:
Erm, using a compare function rather than a key function slows down sorting /significantly/. In fact, the `cmp` parameter to list.sort() has been *removed* in Python 3.0 because of this. Also, top-posting is evil. Please avoid it in the future. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list