Re: SortBy + Sort Strings with apo.marks + CharacterCode
- To: mathgroup at smc.vnet.net
- Subject: [mg118257] Re: SortBy + Sort Strings with apo.marks + CharacterCode
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Mon, 18 Apr 2011 06:50:02 -0400 (EDT)
#1>#2& makes no sense for Strings, because one string is not greater (or less) than another. How is "abcccdde ..." a sorting rule? "b- d-(d) h- characters ?" is just incomprehensible. Bobby On Sun, 17 Apr 2011 18:15:15 -0500, 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 =C5 Cc?? Cc =D0 =A6=A8 \!\(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: [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! > > > -- DrMajorBob at yahoo.com