Re: Sorting a list of pairs on the second elements

*To*: mathgroup at smc.vnet.net*Subject*: [mg51372] Re: Sorting a list of pairs on the second elements*From*: "Peltio" <peltio at twilight.zone>*Date*: Fri, 15 Oct 2004 02:47:12 -0400 (EDT)*References*: <cklmi7$f1o$1@smc.vnet.net>*Reply-to*: "Peltio" <peltioNOSP at Mdespammed.com.invalid>*Sender*: owner-wri-mathgroup at wolfram.com

"János" wrote > Map[Reverse,Sort[Map[Reverse,collectedDnaBin]]] > Sort[collectedDnaBin,#1[[2]] < #2[[2]] &] > but that does not want to do the trick for me. I wonder why. It should work, albeit inefficently. Mmmmm, have you tried with parenthesis wrapped around the pure function? Sort[collectedDnaBin,(#1[[2]] < #2[[2]])&] Have you tried it in a fresh kernel? >In general, if I have a list whose elements are m-member lists, like >{{a1,...,am},...,{z1,...,zm}}, then my question is what is the >best/fastest way to sort it on the k-th elements of the members where >1<=k<=m and ak,...,zk are arbitrary objects - in my case Strings - and >use as little memory for it as possible. Dunno for the general case, but this -very inelegant - approach to sort according to the last element seems to be pretty fast (lots of procedures but applied to the data as a whole, without timeconsuming mapping on every single element) Transpose@Reverse@Transpose@Sort@Transpose@Reverse@Transpose[ collectedDnaBin ] ( The first and last three procs just implement a swap function swap[list_]:=Transpose@Reverse@Transpose[list] ) The group's gurus will certainly find a proc at least ten times faster than this, I'm sure. cheers, Peltio Invalid address in reply-to. Crafty demunging required to mail me.

**Follow-Ups**:**Re: Re: Sorting a list of pairs on the second elements***From:*János <janos.lobb@yale.edu>