MathGroup Archive 2004

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

Search the Archive

Re: sort list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47226] Re: [mg47208] sort list
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Wed, 31 Mar 2004 02:58:16 -0500 (EST)
  • References: <200403300902.EAA06971@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Several possibilities. Example:

In[1]:=
d = {{b, 2}, {a, 5}, {c, 1}};

Sort will perform ordering according to the first element of each list:

In[2]:=
Sort[d]
Out[2]=
{{a,5},{b,2},{c,1}}

You may therefore use any of the following:

In[3]:=
Sort[d, OrderedQ[{#1[[2]], #2[[2]]}] & ]
Out[3]=
{{c,1},{b,2},{a,5}}

In[4]:=
Reverse /@ Sort[Reverse /@ d]
Out[4]=
{{c,1},{b,2},{a,5}}

In[5]:=
RotateLeft /@ Sort[RotateLeft /@ d]
Out[5]=
{{c,1},{b,2},{a,5}}

Tomas Garza
Mexico City
----- Original Message ----- 
From: "Guibout" <guibout at ifrance.com>
To: mathgroup at smc.vnet.net
Subject: [mg47226] [mg47208] sort list


> Hi,
> I have a list of the form 
> {{something1,x1},{something2,x2},{something3,x3}} where x1,x2, x3 are 
> numbers. I want to sort this list with respect to xi. In other word if 
> x2<x3<x1 I want Mathematica to produce:
> {{something2,x2},{something3,x3},{something1,x1}}
> Thanks for your help
> Vincent
> 
> 


  • References:
    • sort list
      • From: Guibout <guibout@ifrance.com>
  • Prev by Date: Re: Constant function Integrate Assumption
  • Next by Date: Re: Expansion of an exponential expression
  • Previous by thread: Re: sort list
  • Next by thread: Re: sort list