Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15605 > unrolled thread

Re: Sorting nested lists with strings

Started byPeter Breitfeld <phbrf@t-online.de>
First post2011-02-10 10:21 +0000
Last post2011-02-10 10:21 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Sorting nested lists with strings Peter Breitfeld <phbrf@t-online.de> - 2011-02-10 10:21 +0000

#15605 — Re: Sorting nested lists with strings

FromPeter Breitfeld <phbrf@t-online.de>
Date2011-02-10 10:21 +0000
SubjectRe: Sorting nested lists with strings
Message-ID<ij0e7g$9c1$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

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web