MathGroup Archive 2000

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

Search the Archive

Re: Sorting

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22104] Re: Sorting
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Mon, 14 Feb 2000 02:03:55 -0500 (EST)
  • References: <8837l8$7o6@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Wagner,

The following works for variables like  abc123 with both letters and
numbers.

sep[{a___Symbol, n___Integer}] :=
  ToExpression[StringJoin @@ ToString /@ #] & /@ {{a}, {n}}

mysort[lst_List] :=
  ToExpression[StringJoin[##]] & @@@ Map[ToString,
      Sort[sep /@ ToExpression /@ Characters /@ ToString /@ lst],
      {2}]

mysort[{z2, a5, z10}]

{a5, z2, z10}

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"Wagner Truppel" <wtruppel at uci.edu> wrote in message
news:8837l8$7o6 at smc.vnet.net...
> 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
>



  • Prev by Date: Simple Problem (I suppose...)
  • Next by Date: Re: Partition
  • Previous by thread: Re: Sorting
  • Next by thread: Re: Sorting