MathGroup Archive 2011

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

Search the Archive

Re: Sorting a list of symbols

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116854] Re: Sorting a list of symbols
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Wed, 2 Mar 2011 04:36:08 -0500 (EST)

On 3/1/11 at 5:22 AM, mathematicauser1 at yahoo.com (Robert Wright)
wrote:

>Is there a way of sorting a list of symbols like {v1, v2, v3, v10,
>v4} such that it gives {v1, v2, v3, v4, v10} and not the Mathematica
>default of {v1,v10, v2,v3, v4}? I am trying to avoid using the
>obvious solution of {v01, v02, v03, v04, v10}!

Yes, it is possible to do this. For example,

In[14]:= list = {v1, v2, v3, v10, v4};
Sort[list, Less @@ ToExpression[StringDrop[ToString@#, 1] & /@
{##}] &]

Out[15]= {v1,v2,v3,v4,v10}

or in a similar vein

In[16]:= list[[Ordering[
    ToExpression[StringDrop[ToString@#, 1] & /@ list]]]]

Out[16]= {v1,v2,v3,v4,v10}



  • Prev by Date: Re: Sorting a list of symbols
  • Next by Date: Re: Bug in Mathematica 8 vs Mathematica 7: SeriesData
  • Previous by thread: Re: Sorting a list of symbols
  • Next by thread: Prepending Data to a File