def neighbours(word):
    for j in range(len(word)):
        for d in string.ascii_lowercase:
            word1 = ''.join(d if i == j else c for i, c in enumerate(word))
if word1 != word and word1 in words:
    yield word1
{word: list(neighbours(word)) for word in words}
Efficiently build a graph of words with given Hamming distance