word_ladder package

Submodules

word_ladder.errors module

exception word_ladder.errors.WordsNotDefined

Bases: Exception

word_ladder.word_ladder module

class word_ladder.word_ladder.Graph(words)

Bases: object

Represents an un-weigthed graph structure with connected words

Parameters:words (iterable) – Words to build the graph with
build(all_lengths=True)

Build the graph

Parameters:all_lengths (bool, optional) – Define if the graph should connect words with different lengths
Returns:dict with the graph structure
class word_ladder.word_ladder.WordLadder(dictionary, start=None, end=None)

Bases: object

Represents a word ladder

Parameters:
  • dictionary (list or str) – Feed with words
  • start (str, optional) – The starting word, Defaults to None
  • end (str, optional) – The ending word, Defaults to None
find_path(start=None, end=None, all_paths=False)

Find the word ladder path

Parameters:
  • start (str, optional) – The starting word, Defaults to None
  • end (str, optional) – The ending word, Defaults to None
  • all_lengths (bool, optional) – Define if the graph should connect words with different lengths
Raises:

WordsNotDefined – If any of the words is None

Returns:

With the word’s path or None

Return type:

(list)

graph

Holds an instance of Graph with the dictionary words

Returns:The graph memoized instance
Return type:(Graph)
words_has_same_length()

Compare length of start and end words

Returns:(bool or None) True, False or None)