Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 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 at 12:54
Yes, sorted in reverse alphabetical order –  Bakkkss Jan 17 at 13:11

1 Answer 1

up vote 4 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. –  rasher Jan 17 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.