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: [mg112285] Re: Sorting a list of names
  • From: Valeri Astanoff <astanoff at gmail.com>
  • Date: Tue, 7 Sep 2010 06:09:18 -0400 (EDT)
  • References: <i64ki5$3c1$1@smc.vnet.net>

On 7 sep, 08:02, 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.=

Good day,

I suggest this way to do it :

In[1]:= names = {"Cole Dockter", "Mackenzie W Christensen",
   "Rebecca Eastham", "David Gartzke",  "Matthew Lundberg",
   "Tyler Hullett", "Cecilia Ford", "Grant A Patterson"};

In[2]:= Sort[names,
 OrderedQ[{StringSplit[#1][[-1]], StringSplit[#2][[-1]]}] &]

Out[2]= {"Mackenzie W Christensen", "Cole Dockter", "Rebecca \
Eastham", "Cecilia Ford", "David Gartzke", "Tyler Hullett", "Matthew \
Lundberg", "Grant A Patterson"}

--
V.Astanoff


  • Prev by Date: Re: user-defined functions in KeyEventTranslations.tr
  • Next by Date: Re: A dragging matter of Interpretation
  • Previous by thread: Re: Sorting a list of names
  • Next by thread: Re: Sorting a list of names