Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Array consists of words of different languages. I need to sort elements in reverse alphabetical order and make a list of elements, which consist of english letters.

Example of array which consist of english and russian words:

m = {"computer", "экзамен", "elephant", "стол", "bread", "телефон", 
   "exception", "desktop", "best", "колонка", "zoom", "saphire", 

Sorting with Reverse@Sort[m] and Sort[m] work with english words only.

Select[m, LetterQ] can make a list of english words.

Problem is a different language (Russian in this e.g.)

share|improve this question
I don't understand this question. Would you please give the output that you require for this sample input? – Mr.Wizard Jan 17 '14 at 12:37
output 1 = {"zoom", "saphire", "exception", "elephant", "desktop", "computer", "bread", "best", "ярость", "экзамен", "телефон", "стол", "колонка"} (reverse alphabetical order) output 2 = {"computer", "elephant", "bread", "exception", "desktop", "best", "zoom", "saphire"} (only english words) – Bakkkss Jan 17 '14 at 12:54
Yes, sorted in reverse alphabetical order – Bakkkss Jan 17 '14 at 13:11
up vote 6 down vote accepted
m = {"computer", "экзамен", "elephant", "стол", "bread", "телефон", "exception",
     "desktop", "best", "колонка", "zoom", "saphire", "ярость"};

First Sort it:

sortedm = SortBy[m, First@ToCharacterCode@# &]
{"best", "bread", "computer", "desktop", "elephant", "exception", "saphire", "zoom",
 "колонка", "стол", "телефон", "экзамен", "ярость"}

Then Split it:

splittedm = {englishWords, russianWords} = SplitBy[sortedm, 
 First@ToCharacterCode@"А" <= (First@ToCharacterCode@#) <= First@ToCharacterCode@"я" &]
{{"best", "bread", "computer", "desktop", "elephant", "exception", "saphire", "zoom"}, 
 {"колонка", "стол", "телефон", "экзамен", "ярость"}}

which can be Reversed & Flattened:

Flatten[Reverse /@ splittedm]
{"zoom", "saphire", "exception", "elephant", "desktop", "computer", "bread", "best",
 "ярость", "экзамен", "телефон", "стол", "колонка"}

giving the desired Output 1.

As you wished you can also extract the English/Russian words (even if they are sorted):

{"best", "bread", "computer", "desktop", "elephant", "exception", "saphire", "zoom"}

To have the unsorted words use:

{unsortedEnglishWords, unsortedRussianWords} = GatherBy[m, 
 First@ToCharacterCode@"А" <= (First@ToCharacterCode@#) <= First@ToCharacterCode@"я" &]

giving the desired Output 2.


The ToCharacterCode@"А" and ToCharacterCode@"я" were taken from the Cyrillic script in Unicode Wiki page assuming that you are using the Basic Cyrillic alphabet.

"А" can be obtained with ToString@\:0410 and "я" with ToString@\:044F. Both letters are meant to be first and last elements of the Basic Cyrillic alphabet.

Other alphabets can be used in the same way.

share|improve this answer
+1 for detailed yet concise answer. – ciao Jan 17 '14 at 23:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.