def ladder_length(begin_word, end_word, word_list):
if len(begin_word) != len(end_word):<EOL><INDENT>return -<NUM_LIT:1>   <EOL><DEDENT>if begin_word == end_word:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>if sum(c1 != c2 for c1, c2 in zip(begin_word, end_word)) == <NUM_LIT:1>:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>begin_set = set()<EOL>end_set = set()<EOL>begin_set.add(begin_word)<EOL>end_set.add(end_word)<EOL>result = <NUM_LIT:2><EOL>while begin_set and end_set:<EOL><INDENT>if len(begin_set) > len(end_set):<EOL><INDENT>begin_set, end_set = end_set, begin_set<EOL><DEDENT>next_begin_set = set()<EOL>for word in begin_set:<EOL><INDENT>for ladder_word in word_range(word):<EOL><INDENT>if ladder_word in end_set:<EOL><INDENT>return result<EOL><DEDENT>if ladder_word in word_list:<EOL><INDENT>next_begin_set.add(ladder_word)<EOL>word_list.remove(ladder_word)<EOL><DEDENT><DEDENT><DEDENT>begin_set = next_begin_set<EOL>result += <NUM_LIT:1><EOL><DEDENT>return -<NUM_LIT:1><EOL>
Bidirectional BFS!!!
:type begin_word: str
:type end_word: str
:type word_list: Set[str]
:rtype: int