Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: Sorting

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22082] Re: [mg22067] Sorting
  • From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
  • Date: Sun, 13 Feb 2000 01:14:00 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

on 00.2.12 6:04 PM, Wagner Truppel at wtruppel at uci.edu wrote:

> Hi folks,
> 
> can anyone tell me how I can make Mathematica sort variable names
> without sorting any numbers within those variables as strings as
> well? If you try Sort[{z2,a5,z10}] you get back {a5,z10,z2}, while I
> want to get back {a5,z2,z10}.
> 
> Thanks.
> Wagner Truppel
> wtruppel at uci.edu
> 
The following is probably not nor most efficient way to do this but it seems
to work:

mysort[l_List] := 
  Block[{a, x}, 
    Map[ToExpression,
      Map[StringJoin,
        Map[ToString,
          Sort[Map[ToExpression,
                Map[Characters[ToString[#]] &, l], {-1}] /. {a_Symbol,
                  x__?NumberQ} -> {a, {x}}], {-1}]]]]

In[6]:=
mysort[{a3, z5, z17, a9, b19, b7}]

Out[6]=
{a3, a9, b7, b19, z5, z17}

while

In[8]:=
Sort[{a3, z5, z17, a9, b19, b7}]

Out[8]=
{a3, a9, b19, b7, z17, z5}


--
Andrzej Kozlowski
Toyama International University
Toyama, Japan
http://sigma.tuins.ac.jp/




  • Prev by Date: string + variable order
  • Next by Date: Re: Sorting
  • Previous by thread: Sorting
  • Next by thread: Re: Sorting