Re: Sorting a list of names
- To: mathgroup at smc.vnet.net
- Subject: [mg112279] Re: Sorting a list of names
- From: Adriano Pascoletti <adriano.pascoletti at uniud.it>
- Date: Tue, 7 Sep 2010 06:08:13 -0400 (EDT)
Use SortBy: In[2]:= SortBy[names, Last[StringSplit[#1, " "]] & ] Out[2]= {"Mackenzie Christensen", "Cole Dockter", "Rebecca Eastham", "Cecilia Ford", "David Gartzke", "Tyler Hullett", "Matthew \ Lundberg", "Grant Patterson"} Adriano Pascoletti On 20100907, at 08.02, Jon Joseph wrote: > All: I have a list of names read in as strings with first names first. > Can anyone suggest a mechanism to sort the list by the last names with > the final output being the entire name? > > Starting array: > > names = {"Cole Dockter", "Mackenzie Christensen", "Rebecca Eastham", > "David Gartzke", \ > "Matthew Lundberg", "Tyler Hullett", "Cecilia Ford", "Grant Patterson"} > > Ending array: > > names_sorted = {"Mackenzie Christensen", "Cole Dockter", "Rebecca > Eastham", "Cecilia Ford", "David Gartzke", "Tyler Hullett", "Matthew > Lundberg", "Grant Patterson"} > > As a note Sort[StringSplit[names][[All, 2]]] does exactly what I want > except it drops the first name on output.= >