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: [mg116827] Re: Sorting a list of symbols
  • From: Heike Gramberg <heike.gramberg at gmail.com>
  • Date: Wed, 2 Mar 2011 04:31:14 -0500 (EST)

The only way I can think of for your specific example is using something like

In[110]:= f[p_] := ToExpression[StringDrop[SymbolName[p], 1]]
g[lst_] := Sort[lst, (f[#1] <= f[#2] &)]

In[112]:= g[{v1, v5, v2, v10, v3}]

Out[112]= {v1, v2, v3, v5, v10}

Heike.

On 1 Mar 2011, at 10:22, 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}!


  • Prev by Date: Re: Sorting a list of symbols
  • Next by Date: Re: Sorting a list of symbols
  • Previous by thread: Re: Sorting a list of symbols
  • Next by thread: Re: Sorting a list of symbols