Try now in the
Open Cloud »
(no sign-in required)

# Palindromes of English

Find the words in English that read the same backward and forward.

Run the code to reverse the word rhinoceros. Try other words, like your name:

rhinoceros is a string of letters: the quotes mean that its text, not a computer command.

StringReverse is a Wolfram Language function that reverses a string.

The output doesnt display quotes, but its a string too.

 In[1]:= XStringReverse["rhinoceros"]
 Out[1]=

Get a list of dictionary words in English:

Note: the list is automatically shortened because it is very long.

 In[1]:= XDictionaryLookup[]
 Out[1]=

Select words that have length 10. Try other lengths:

StringLength gives the length of a string in characters:

 In[1]:= XStringLength["abcd"]
 Out[1]=

x==y tests if x and y are equal (note that single = means something completely different):

 In[2]:= X4 == 6
 Out[2]=
 In[3]:= X5 == 5
 Out[3]=

Select selects elements from a list according to a criterion (EvenQ tests whether a number is even):

 In[4]:= XSelect[{1, 2, 3, 4, 5, 6, 7}, EvenQ]
 Out[4]=

Weve got to make up our own criterion for Select. To do that, we use a pure function, indicated by # and &:

 In[5]:= XSelect[{"the", "cat", "in", "the", "hat"}, StringLength[#] == 3 &]
 Out[5]=

 In[1]:= XSelect[DictionaryLookup[], StringLength[#] == 10 &]
 Out[1]=

Find the palindromes of English:

 In[1]:= XSelect[DictionaryLookup[], StringReverse[#] == # &]
 Out[1]=

Find palindromes with all letters made lower case:

Make a word all lower case:

 In[1]:= XToLowerCase["Bill"]
 Out[1]=

Make a word all upper case:

 In[2]:= XToUpperCase["attention!"]
 Out[2]=

 In[1]:= XSelect[ToLowerCase[DictionaryLookup[]], StringReverse[#] == # &]
 Out[1]=

Sort by string length:

Sort a list of words alphabetically:

 In[1]:= XSort[{"fish", "elephant", "cow", "horse"}]
 Out[1]=

Sort a list of words by length:

 In[2]:= XSortBy[{"fish", "elephant", "cow", "horse"}, StringLength]
 Out[2]=

 In[1]:= XSortBy[Select[ToLowerCase[DictionaryLookup[]], StringReverse[#] == # &], StringLength]
 Out[1]=