Spelling Bee Solver

A solver for the New York Times puzzle "Spelling Bee".


In [2]:
def get_matching_words(center_letter, other_letters, min_word_length=5):
    words = []
    allowed_letters = set(center_letter).union(set(other_letters))
    with open('/usr/share/dict/american-english', 'r') as f:
        for word in f:
            word = word.strip().lower()
            if len(word) < min_word_length:
                continue
            if center_letter not in word:
                continue
            if set(word).difference(allowed_letters):
                # the word contains letters other than the allowed letters
                continue
            words.append(word)
    return words

matching_words = get_matching_words('t', ('a', 'b', 'e', 'k', 'm', 'n'))
matching_words


Out[2]:
['annette',
 'atman',
 'bataan',
 'batman',
 'benet',
 'bennett',
 'bette',
 'emmett',
 'mamet',
 'manet',
 'menkent',
 'nanette',
 'tameka',
 'abate',
 'abatement',
 'antenna',
 'antennae',
 'bantam',
 'batten',
 'beaten',
 'betake',
 'betaken',
 'eaten',
 'emanate',
 'embankment',
 'enemata',
 'entente',
 'manatee',
 'matte',
 'meant',
 'taken',
 'teammate',
 'tenant',
 'tenement',
 'tenet']

In [ ]:


In [ ]: