MathGroup Archive 2005

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

Search the Archive

Re: Sorting nested list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57462] Re: Sorting nested list
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Sat, 28 May 2005 05:40:12 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 5/27/05 at 4:56 AM, plizak at gmail.com (plizak) wrote:

>I have a similar problem, I need to sort the same kind of list

>{{a,{2,4,1.,...}}, {c, {1,2,...}},{b,{3.2,-2,.â? ..}}}

>but I need to sort it based on the first element of each subarray,
>while keeping the second element the same.

>I did a pretty ugly solution (like 12 lines of code).  Is there a
>quicker more elegant way to sort this?

Is this what you want?

In[8]:=
data = {{a, {2, 4, 1.}}, {c, {1, 2}}, {b, {3.2, -2}}}; 
Sort[data, OrderedQ[{#1[[2,1]], #2[[2,1]]}] & ]

Out[9]=
{{c, {1, 2}}, {a, {2, 4, 1.}}, {b, {3.2, -2}}}
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: pure functions vs. functions
  • Next by Date: Re: restricting range?
  • Previous by thread: Re: Sorting nested list
  • Next by thread: Re: Sorting nested list