Wolfram Archive
Wolfram Programming Lab is a legacy product.
All the same functionality and features, including access to Programming Lab Explorations, are available with Wolfram|One.
Start programming now. »

Words Near Your Name

Find words that differ from your name by the fewest characters.

Run this code to get a list of dictionary words:

SHOW/HIDE DETAILS

This returns a list of all the words in the dictionary. The list is automatically shortened because it is very long:

DictionaryLookup[]

You can select particular words by giving DictionaryLookup a word pattern.

This gives the list of words that begin with soph:

DictionaryLookup["soph" ~~ ___]

HIDE DETAILS
DictionaryLookup[]

Compute how many characters have to be edited to get from rhino to rhyno. Try different words:

SHOW/HIDE DETAILS

EditDistance tells you how many characters you have to edit to get from one word to another.

You have to make one edit to change rhino to rhyno (change i to y):

EditDistance["rhino", "rhyno"]

You have to make two edits to change fish to fin (delete h and change s to n):

EditDistance["fish", "fin"]

HIDE DETAILS
EditDistance["rhino", "rhyno"]

Find words that differ by fewer than three edits from sophia. Try other names:

SHOW/HIDE DETAILS

Select selects items in a list that pass a test.

This selects words whose lengths are less than 4 characters:

Select[{"fish", "cat", "owl", "snake", "deer"}, StringLength[#] < 4 &]

The test StringLength[#]<4& is whats called a pure function. When its used in Select, each item in turn in the list replaces the hash sign (#), and the function returns True if that items length is less than 4, and otherwise False. Items that return True are selected and those that return False are rejected.

Use Select to select dictionary words whose distance from sophia is less than 3 edits:

Select[DictionaryLookup[], EditDistance["sophia", #] < 3 &]

HIDE DETAILS
Select[DictionaryLookup[], EditDistance["sophia", #] < 3 &]

Find collections of words that differ by edit distances up to 3 from sophia. Try other names or words:

SHOW/HIDE DETAILS

Table makes lists of things.

This uses Table to make a list of the first three even numbers:

Table[2 n, {n, 3}]

This makes a list of lists. Each list is the numbers from 1 to n as n goes from 1 to 3:

Table[Range[n], {n, 3}]

This makes a list of lists of words whose edit distances from sophia are n as n goes from 1 to 3:

Table[Select[DictionaryLookup[], EditDistance["sophia", #] == n &], {n, 3}]

HIDE DETAILS
Table[Select[DictionaryLookup[], EditDistance["sophia", #] == n &], {n, 3}]

Format the result as a grid:

SHOW/HIDE DETAILS

Include the edit distance in the list of results:

Table[{n, Select[DictionaryLookup[], EditDistance["sophia", #] == n &]}, {n, 3}]

Format the result as a grid with edit distances in the first column and words in the second:

Grid[Table[{n, Select[DictionaryLookup[], EditDistance["sophia", #] == n &]}, {n, 3}]]

Align the grid columns on the left:

Grid[Table[{n, Select[DictionaryLookup[], EditDistance["sophia", #] == n &]}, {n, 3}], Alignment -> Left]

Add divider lines to make the grid more readable:

Grid[Table[{n, Select[DictionaryLookup[], EditDistance["sophia", #] == n &]}, {n, 3}], Alignment -> Left, Dividers -> All]

HIDE DETAILS
Grid[Table[{n, Select[DictionaryLookup[], EditDistance["sophia", #] == n &]}, {n, 3}], Alignment -> Left, Dividers -> All]

Share Itmake a website to find words near your name:

SHOW/HIDE DETAILS

Deploy a form that asks for a name and gives a table of words near it:

CloudDeploy[FormFunction[{"name" -> "String"}, With[{name = #name}, Grid[Table[{n, Select[DictionaryLookup[], EditDistance[name, #] == n &]}, {n, 3}], Alignment -> Left, Dividers -> All] ] &, "PNG"], "Permissions" -> "Public" ]

Click the link in the output to visit the site.

Tell the world about your creation by sharing the link via email, tweet or other message.

HIDE DETAILS
CloudDeploy[FormFunction[{"name" -> "String"}, With[{name = #name}, Grid[Table[{n, Select[DictionaryLookup[], EditDistance[name, #] == n &]}, {n, 3}], Alignment -> Left, Dividers -> All] ] &, "PNG"], "Permissions" -> "Public" ]