Wolfram Mathematica

Sorting Cities and Building a Dictionary

In Version 11, it is possible to sort strings using an alphabetic comparison method defined for each language.

For example, get a group of cities from Denmark.

In[1]:=
```cityNames = EntityValue[ GeoEntities[ Entity["AdministrativeDivision", {"Nordjylland", "Denmark"}], "City"], "Name"];```

Now sort these cities using AlphabeticSort but setting the languages separately to Danish and English, to be able to appreciate the differences between them.

In[2]:=
```sortedCityNames = Transpose[{AlphabeticSort[cityNames, "Danish"], AlphabeticSort[cityNames, "English"]}];```
show complete Wolfram Language input
In[3]:=
```TextGrid[Join[ Sequence @@ (Prepend[#, {"Danish", "English"}] & /@ Partition[sortedCityNames, UpTo[14]]), 2], Frame -> {None, None, {{{1, 1}, {1, 6}} -> True, {{1, 15}, {1, 6}} -> True, {{1, 15}, {1, 2}} -> True, {{1, 15}, {1, 4}} -> True}}]```
Out[3]=

Create a sorted dictionary translating a random sample of words from Swedish to English.

In[4]:=
```words = AlphabeticSort[ RandomSample[WordList[Language -> "Swedish"], 6], "Swedish"];```
In[5]:=
```sortedTranslations = AlphabeticSort[#, "English"] & /@ WordTranslation[words, "Swedish" -> "English"];```
show complete Wolfram Language input
In[6]:=
`TextGrid[{words, Column /@ sortedTranslations}, Frame -> All]`
Out[6]=