Re: Sorting nested lists with strings
- To: mathgroup at smc.vnet.net
- Subject: [mg116296] Re: Sorting nested lists with strings
- From: Peter Breitfeld <phbrf at t-online.de>
- Date: Thu, 10 Feb 2011 05:22:01 -0500 (EST)
- 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