Word ladder

Write ladder_length(start, end, words) that returns the length (number of words, including both ends) of the shortest sequence from start to end where each step changes exactly one letter and every intermediate word is in words. end must be in words. Return 0 if no such sequence exists.

ladder_length("hit", "cog", ["hot", "dot", "dog", "lot", "log", "cog"])  ->  5     (hit, hot, dot, dog, cog)
ladder_length("hit", "cog", ["hot", "dot", "dog", "lot", "log"])         ->  0

BFS where the neighbours of a word are generated by trying every letter in every position and keeping those in the word set.

def ladder_length(start, end, words):
    ...