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:

SHOW/HIDE DETAILS

"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.

HIDE DETAILS
StringReverse["rhinoceros"]

Get a list of dictionary words in English:

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

DictionaryLookup[]

Select words that have length 10. Try other lengths:

SHOW/HIDE DETAILS

StringLength gives the length of a string in characters:

StringLength["abcd"]

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

4 == 6
5 == 5

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

Select[{1, 2, 3, 4, 5, 6, 7}, EvenQ]

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

Select[{"the", "cat", "in", "the", "hat"}, StringLength[#] == 3 &]

HIDE DETAILS
Select[DictionaryLookup[], StringLength[#] == 10 &]

Find the palindromes of English:

Select[DictionaryLookup[], StringReverse[#] == # &]

Find palindromes with all letters made lowercase:

SHOW/HIDE DETAILS

Make a word all lowercase:

ToLowerCase["Bill"]

Make a word all uppercase:

ToUpperCase["attention!"]

HIDE DETAILS
Select[ToLowerCase[DictionaryLookup[]], StringReverse[#] == # &]

Sort by string length:

SHOW/HIDE DETAILS

Sort a list of words alphabetically:

Sort[{"fish", "elephant", "cow", "horse"}]

Sort a list of words by length:

SortBy[{"fish", "elephant", "cow", "horse"}, StringLength]

HIDE DETAILS
SortBy[Select[ToLowerCase[DictionaryLookup[]], StringReverse[#] == # &], StringLength]