word_ladder package¶
Submodules¶
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 lengthsReturns: 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
orstr
) – 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 NoneReturns: With the word’s path or None
Return type: (
list
)- start (
-
graph
¶ Holds an instance of
Graph
with the dictionary wordsNote
when setting words an internal hash value is created for caching purpose, so we don’t process the grah again if there is a serialzed version of the graph object
Returns: The graph memoized instance Return type: ( Graph
)
-
tmp
= ‘/tmp’¶
-
words
¶ Holds the list of words
Returns: ( list
) The list of words
-
words_has_same_length
()¶ Compare length of start and end words
Returns: ( bool
orNone
) True, False or None)
- dictionary (