Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #15919 > unrolled thread
| Started by | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| First post | 2011-02-10 10:22 +0000 |
| Last post | 2011-02-10 10:22 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: Sorting nested lists with strings Bill Rowe <readnews@sbcglobal.net> - 2011-02-10 10:22 +0000
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Date | 2011-02-10 10:22 +0000 |
| Subject | Re: Sorting nested lists with strings |
| Message-ID | <ij0e9o$9e0$1@smc.vnet.net> |
On 2/9/11 at 2:09 AM, kgodelNOSPAM@liberoNOSPAM.it (Paperorbifold)
wrote:
>I've a nested list of this kind:
>list={{"Paul",23},{"Amanda",55},{"Carl",32},...} Suppose I want to
>perform an alphabetic sort on the first element. Which is the
>condition I've to write in Sort[list,...]? Actually Sort[list]
>automatically operates on the second element.
What??? Not here
In[1]:= list = {{"Paul", 23}, {"Amanda", 55}, {"Carl", 32}};
In[2]:= Sort[list]
Out[2]= {{"Amanda", 55}, {"Carl", 32}, {"Paul", 23}}
But I can sort by the second element by either using a pure
function or by using SortBy
In[3]:= Sort[list, Last@#1 < Last@#2 &]
Out[3]= {{"Paul", 23}, {"Carl", 32}, {"Amanda", 55}}
In[4]:= SortBy[list, Last]
Out[4]= {{"Paul", 23}, {"Carl", 32}, {"Amanda", 55}}
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web