Re: SortBy + Sort Strings with apo.marks + CharacterCode
- To: mathgroup at smc.vnet.net
 - Subject: [mg118261] Re: SortBy + Sort Strings with apo.marks + CharacterCode
 - From: Bob Hanlon <hanlonr at cox.net>
 - Date: Mon, 18 Apr 2011 06:50:45 -0400 (EDT)
 
As stated in the documentation: "Greater gives True or False when its arguments are real numbers."
Using Greater with strings doers not evaluate.
"January" > "February"
"January" > "February"
Use Order
list = {"January", "February", "March", "April",
   "May", "June", "July", "August", "September",
   "October", "November", "December", "English"};
Sort[list] ==
 Sort[list, Order[#1, #2] == 1 &] ==
 list[[Ordering[list]]]
True
Bob Hanlon
---- "Dr Andy D Kucar P2EE4 www.radio4u.com" <andy at radio4u.com> wrote:
==========================
Dear Mathgroup,
Following on the original SortBy post and responses,
I would like to expand with the following (Ver.4) funs
In[17]
Sort[{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",
"December", "English"}]
Sort[{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",
"December", "English"}, #1 > #2 & ]
ToCharacterCode[{"A2Z a2z =C3=85  Cc?? Cc =C3=90 =C2=8A=C2=9A \!\(Z\&?\)\!\(z\&?\)"}]
Out[17]
{"April", "August", "December", "English", "February", "January", "July", "June", "March", "May", "November", "October",
"September"}
this is OK
Out[18]
{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",
"December", "English"}
this is NOT ok; #1>#2 & has been ignored; the input has NOT been evaluated, i.e. sorted;
why?
How to Sort these String things?
Out[19]
{{65, 50, 90, 32, 97, 50, 122, 32, 197, 32, 268, 269, 32, 262, 263, 32, 208, 32, 352, 353, 32, 63425, 63433, 90, 63431,
780, 63424, 63425, 63433, 122, 63431, 780, 63424}}
this ToCharacterCode conversion is OK;
however, I have been using a text with some international characters, which require sorting rules different from the
rule presented in Mathematica;
For example, one would like to sort a particular String according to the following sorting rule: abcccdde ...
One of (perhaps easiest) sorting possibilities would be, having been able to define a sorting rule,
or redefine the CharacterCode and give it a real (rational) number,
such as c (change in a program its CharacterCode from 269 to 99.1, or 99+269/1000, a CharacterCode number between c and
d), etc.
particularly problematic have been characters created via (Ctrl+& Esc hc Esc) construction
how to create b- d-(d) h- characters ?
thank you, sincerely andy
-----Original Message-----
From: graser
Sent: Friday, April 15, 2011 02:57
To: mathgroup at smc.vnet.net
Subject: [mg118261] [mg118247] SortBy
Dear Mathematica group,
I have a simple question for you.
Let's say there is a list like
KS = {{300, 48, 2}, {500, 23, 5}, {120, 55, 7}, {40, 32, 1}};
I want to sort it by second element.
I can use
Sort[KS, #2[[2]] > #1[[2]] &]
It gives out like
{{500, 23, 5}, {40, 32, 1}, {300, 48, 2}, {120, 55, 7}}
But if I want to use SortBy, how to do that?
SortBy[KS, ??]
Thanks!