Mathematica 9 is now available
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 smc.vnet.net
  • Subject: [mg112312] Re: Sorting a list of names
  • From: Simon <simonjtyler at gmail.com>
  • Date: Thu, 9 Sep 2010 04:21:31 -0400 (EDT)
  • References: <i64ki5$3c1$1@smc.vnet.net> <i652vt$9uk$1@smc.vnet.net>

On Sep 7, 8:09 pm, Simon <simonjty... at gmail.com> wrote:
> On Sep 7, 4:02 pm, Jon Joseph <josco.... at gmail.com> 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.=
>
> Try
> SortBy[names, Reverse[StringSplit[#]] &]
> It will sort by Last name then first name.
>
> If you have names with more than two parts you might want to be a
> little more sensible about the way you store the data.
> It's normally best to sort the Surname and the Given names separately.

Actually, it's probably best to SortBy using
In[1]:= RotateRight[StringSplit["Some Big Long Name"]]
Out[1]= {Name,Some,Big,Long}


  • Prev by Date: Re: Collecting Positive and Negative Terms
  • Next by Date: Re: Finite Groups...infinite disappoinment
  • Previous by thread: Re: Sorting a list of names
  • Next by thread: Make a nested list in a loop!