|
[Date Index]
[Thread Index]
[Author Index]
Re: Sort problem
- To: mathgroup at smc.vnet.net
- Subject: [mg81732] Re: Sort problem
- From: Bill Rowe <readnewsciv at sbcglobal.net>
- Date: Tue, 2 Oct 2007 05:43:23 -0400 (EDT)
On 10/1/07 at 4:49 AM, donabc at comcast.net (Donald DuBois) wrote:
>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?
In the first example above, no specific sort function is
specified, so Mathematica puts the items in canonical order. In
the second example, you have specified a pure function as the
test function and given none of the symbols have assigned values
the function returns neither true nor false. Consequently, the
order is unchanged.
You can achieve what you want with:
In[3]:= data = {{r, 2}, {a, 3}, {x, 4}};
data[[Ordering[First /@ data]]]
Out[4]= {{a, 3}, {r, 2}, {x, 4}}
--
To reply via email subtract one hundred and four
Prev by Date:
Re: Sort problem
Next by Date:
Re: Other bug in ContourPlot
Previous by thread:
Re: Sort problem
Next by thread:
Re: Sort problem
|