MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Sorting a list of pairs on the second elements

"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)

collectedDnaBin ]

( The first and last three procs just implement a swap function

The group's gurus will certainly find a proc at least ten times faster than
this, I'm sure.

Invalid address in reply-to. Crafty demunging required to mail me.

  • Prev by Date: Question about derivatives
  • Next by Date: Re: FilledPlot Sideways?
  • Previous by thread: Re: Sorting a list of pairs on the second elements
  • Next by thread: Re: Re: Sorting a list of pairs on the second elements