Re: Sort problem

*To*: mathgroup at smc.vnet.net*Subject*: [mg81739] Re: Sort problem*From*: Szabolcs Horvát <szhorvat at gmail.com>*Date*: Tue, 2 Oct 2007 05:46:59 -0400 (EDT)*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? > This is because "r < a" does not evaluate to False or True. You don't need anything special to make Sort[] work in this example: In[1]:= Sort[{{r, 2}, {a, 3}, {x, 4}}] Out[1]= {{a, 3}, {r, 2}, {x, 4}} The correct version of In[33] from your message would be: In[2]:= Sort[{{r, 2}, {a, 3}, {x, 4}}, OrderedQ[{#1[[1]], #2[[1]]}] & ] Out[2]= {{a, 3}, {r, 2}, {x, 4}} -- Szabolcs