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

MathGroup Archive 2007

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

Search the Archive

Re: Sort problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81743] Re: Sort problem
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 2 Oct 2007 05:49:03 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fdqd33$n6m$1@smc.vnet.net>

Donald DuBois wrote:
> Hello,
> 
> This Sort works
> 
> In[32]:= Sort[{r, a, x}]
> 
> Out[32]= {a, r, x}
> 
> but this one doesn't:
> 
> In[33]:= Sort[{{r, 2}, {a, 3}, {x, 4}}, #1[[1]] < #2[[1]] &]
> 
> Out[33]= {{r, 2}, {a, 3}, {x, 4}}
> 
> 
> What am I doing wrong?

Using inequalities on purely alphabetic symbol. Use either nothing (as 
long as you want the list sorted according to its first column) or 
*OrderedQ* as in the following examples.

In[1]:= Sort[{{r, 2}, {a, 3}, {x, 4}}]

Out[1]= {{a, 3}, {r, 2}, {x, 4}}

In[2]:= Sort[{{r, 2}, {a, 3}, {x, 4}}, OrderedQ[{#1[[1]], #2[[1]]}] &]

Out[2]= {{a, 3}, {r, 2}, {x, 4}}

Regards,
-- 
Jean-Marc


  • Prev by Date: Re: Equivalent functionality to colorbar in Mathematica?
  • Next by Date: Re: Sort problem
  • Previous by thread: Re: Sort problem
  • Next by thread: Re: Sort problem