Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2013

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

Search the Archive

Re: sorting?

  • To: mathgroup at
  • Subject: [mg129603] Re: sorting?
  • From: Francisco Gutierrez <fgutiers2002 at>
  • Date: Mon, 28 Jan 2013 02:26:02 -0500 (EST)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • References: <kdvtkk$fp2$> <>
  • Reply-to: Francisco Gutierrez <fgutiers2002 at>

Works perfect Albert, thanks!

From: awnl <awnl at>
To: mathgroup at 
Sent: Saturday, January 26, 2013 4:59 PM
Subject: [mg129603] Re: sorting?


> I have a large list of simple numerical lists, and I want to sort it
> using two criteria. in the simplest case, suppose the sublists are of
> length two, and that my first criterion is the quotient of part one
> by part two, and my second criterion is the size of part two (no
> zeros in part 2.  I want to sort using the first criterion, and then
> break the ties using the second one. So for example if I had
> lalista={{0,5},{8,8},{2,2},{3,5},{1,3},{3,9}}, the sorting should
> return

> {{8,8},{2,2},{3,5},{3,9},{1,3},{0,5}}

> Of course this can be done, but I wonder if it is a way to make this
> only with native Mathematica tools (wich is always far more
> efficient).

I think you are looking for SortBy, which can be given a list of pure 
functions to define the sorting, e.g. like this (the minus signs reverse 
the sorting so I get what you want, it might need adoption depending on 
what you really want...):

SortBy[lalista, {-#[[1]]/#[[2]] &, -#[[2]] &}]



  • Prev by Date: Matrix elimination
  • Next by Date: Using Wolfram Alpha in a nested loop
  • Previous by thread: Re: sorting?
  • Next by thread: sorting