Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: sorting?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg129589] Re: sorting?
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Sat, 26 Jan 2013 16:58:26 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <20130126063956.0BD5E68E1@smc.vnet.net>

lalista = {{0, 5}, {8, 8}, {2, 2}, {3, 5}, {1, 3}, {3, 9}};

SortBy[lalista, (Divide @@ #) + 10^-6*#[[2]] &] // Reverse

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


Bob Hanlon


On Sat, Jan 26, 2013 at 1:39 AM, Francisco Gutierrez
<fgutiers2002 at yahoo.com> wrote:
>
> Friends:
> 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).
>
> Thanks for your help
>
> Francisco
>



  • Follow-Ups:
    • Re: sorting?
      • From: Francisco Gutierrez <fgutiers2002@yahoo.com>
  • References:
    • sorting?
      • From: Francisco Gutierrez <fgutiers2002@yahoo.com>
  • Prev by Date: Re: something wrong with my code??
  • Next by Date: Re: Question about Thread & Total
  • Previous by thread: sorting?
  • Next by thread: Re: sorting?