Skip to content

Instantly share code, notes, and snippets.



Last active Jan 5, 2020
What would you like to do?

word chain challenge

Given a wordlist (say, the English dictionary), if you can remove a letter from a word and the new word is a known word (in the wordlist), this makes a chain of length 2. If you can repeat this for a second time, you continue to the third level, and so on.

For example, the word "trees" has a chain length of 3:

Using the system dictionary (code snippet provided), how long is the longest chain? And which words make the longest chain?

Get started

from words import WORDS
alphabet = 'qwertyuiopasdfghjklzxcvbnm'
with open('/usr/share/dict/british-english') as f:
for word in f
if all(c in alphabet for c in word.strip())
print(len(WORDS), 'words')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment