Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Sorting a list of names

  • To: mathgroup at
  • Subject: [mg112287] Re: Sorting a list of names
  • From: Albert Retey <awnl at>
  • Date: Tue, 7 Sep 2010 06:17:45 -0400 (EDT)
  • References: <i64ki5$3c1$>

Am 07.09.2010 08:02, schrieb Jon Joseph:
> 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.=

I think:

SortBy[names, Last[StringSplit[#]] &]

would probably the most obvious thing to use (using Last instead of
[[2]] might be more robust when there are middle names or missing first



  • Prev by Date: Re: Sorting a list of names
  • Next by Date: Re: Finite Groups...infinite disappoinment
  • Previous by thread: Re: Sorting a list of names
  • Next by thread: Re: Sorting a list of names