MathGroup Archive 2007

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

Search the Archive

Re: Sort problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81719] Re: [mg81678] Sort problem
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Tue, 2 Oct 2007 05:36:40 -0400 (EDT)
  • References: <29806953.1191260945481.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

The default Sort criterion is OrderedQ[{#1,#2}]& (canonical ordering) and  
that's quite different from #1 < #2 & (Less). r < a is neither True nor 
False (unless r and a are numbers), so in your example it doesn't cause 
elements to be switched in the sort process.

Here are a couple of ways to get what you seem to want:

Sort[{{r, 2}, {a, 3}, {x, 4}}, OrderedQ[First /@ {##}] &]

{{a, 3}, {r, 2}, {x, 4}}

SortBy[{{r, 2}, {a, 3}, {x, 4}}, First]

{{a, 3}, {r, 2}, {x, 4}}

Bobby

On Mon, 01 Oct 2007 03:49:55 -0500, Donald DuBois <donabc 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
>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Palette Size
  • Next by Date: Re: Other bug in ContourPlot
  • Previous by thread: Re: Sort problem
  • Next by thread: StatusArea