Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #15605
| From | Peter Breitfeld <phbrf@t-online.de> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Sorting nested lists with strings |
| Date | 2011-02-10 10:21 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <ij0e7g$9c1$1@smc.vnet.net> (permalink) |
| References | <iitejq$jib$1@smc.vnet.net> |
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.
> Thanks.
>
> --
> ...and I will make them pay for\nwhat they've done! (J.L. Picard)
>
You may try
list = {{"Paul", 23}, {"Gustaf", 45}, {"Wilhelm", 13}, {"Arno", 45}};
list[[ Ordering[First/@list] ]]
Out={{"Arno", 45}, {"Gustaf", 45}, {"Paul", 23}, {"Wilhelm", 13}}
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Sorting nested lists with strings Peter Breitfeld <phbrf@t-online.de> - 2011-02-10 10:21 +0000
csiph-web