def DifferentByOne(word1, word2):
    if word1[0] != word2[0]:
        return word1[1:] == word2[1:]
different = False
for i in range(1, len(word1)):
    if word1[i] != word2[i]:
        if different:
            return False
different = True
return different
How can I optimize this Python code to generate all words with word-distance 1?