Re: Sort problem
- To: mathgroup at smc.vnet.net
- Subject: [mg81725] Re: Sort problem
- From: Aranthon <a.dwarf at gmail.com>
- Date: Tue, 2 Oct 2007 05:39:46 -0400 (EDT)
- References: <fdqd33$n6m$1@smc.vnet.net>
On Oct 1, 5:02 am, Donald DuBois <don... at comcast.net> 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?
>
> Don
The problem is that since you're sorting symbols, Less is the wrong
ordering function.
If you use OrderedQ[{First[#1],First[#2]}]&, it'll work (in fact, you
can get away with just OrderedQ[{#1,#2}]& )
Greg