MathGroup Archive 2000

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

Search the Archive

Re: Sorting

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22110] Re: [mg22067] Sorting
  • From: "Christopher French" <clfrench at msn.com>
  • Date: Mon, 14 Feb 2000 02:04:02 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Wagner,

I know that you already received several answers to you post but this seemed
like such a fun problem that I could not resist. You are trying to get Sort
to ignore digit strings while sorting lists of strings that represent
symbols. One way to do this is to create a function for Sort to use on your
input. For example

Sort[ {"z2", "a5", "z10"}, (OrderedQ[{#2, #1}]&)]

will cause your result to be the same as

Reverse[ Sort[ {"z2", "a5", "z10"} ] ].

For your situation you want sorting to proceed as normal on elements with
the number strings stripped from the arguments. This is the result that you
gave in your example.

 Sort[{"z2","a5","z10"}]

{"a5","z10","z2"}

This is a function that you can give to Sort that will strip the digits from
the strings (in place) before testing them.
(please excuse the eccentric programming style, I tent to prefer writing
post-fix pure functions)

 noDigits=
 {##}
   //Characters/@#&
   //DeleteCases[#,_?DigitQ]&/@#&
   //StringJoin@@#&/@#&
   //OrderedQ
   //Function;

This is the same pure function using prefix notation.

noDigits=
OrderedQ[
((StringJoin@@#&)/@#&)[
((DeleteCases[#,_?DigitQ]&)/@#&)[
(Characters/@#&)[{##}]]]]&;

Now, Sort gives the output that matches the kind that you requested.

Sort[{"z2","a5","z10"}, noDigits]
{"a5","z2","z10"}

Christopher Lee French
<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>
The secret of magnetism, now explain that to me!
There is no greater secret, except love and hate.

                               Johann Wolfgang Von Gothe
-----Original Message-----
From: Wagner Truppel <wtruppel at uci.edu>
To: mathgroup at smc.vnet.net
Subject: [mg22110] [mg22067] Sorting


>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: Re: global real variables
  • Next by Date: What is happening here?
  • Previous by thread: Re: Sorting
  • Next by thread: Sorting