word_ladder Documentation - Word Ladder

23
word_ladder Documentation Release 0.0.1 Sven Nebel Jun 02, 2017

Transcript of word_ladder Documentation - Word Ladder

word_ladder DocumentationRelease 0.0.1

Sven Nebel

Jun 02, 2017

Contents:

1 Prerequisites 3

2 Installing 52.1 Production . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 Getting started 73.1 Command line tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2 Python module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

4 Running the tests 9

5 References 11

6 word_ladder CLI 13

7 word_ladder package 157.1 Submodules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157.2 word_ladder.errors module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157.3 word_ladder.word_ladder module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Python Module Index 17

i

ii

word_ladder Documentation, Release 0.0.1

Find path from one word to another, changing one letter each step, and each intermediate word must be in the dictio-nary, the dictionary is a text file with words separated by a line break like the one found in /usr/share/dict/words

Contents: 1

word_ladder Documentation, Release 0.0.1

2 Contents:

CHAPTER 1

Prerequisites

• Python 3.4 and Linux

• List of words separated by newlines

• Virtual environment is recommended

3

word_ladder Documentation, Release 0.0.1

4 Chapter 1. Prerequisites

CHAPTER 2

Installing

Clone the repository (Pypi package comming soon)

$ git clone [email protected]:snebel29/word_ladder.git$ cd word_ladder

2.1 Production

$ pip install .

2.2 Development

$ pip install -e .[dev]

5

word_ladder Documentation, Release 0.0.1

6 Chapter 2. Installing

CHAPTER 3

Getting started

The word_ladder packges commes with both, a command line tool and a module that can be used to find word ladderpaths

3.1 Command line tool

Once installed you can use the command line interface

$ word_ladder -h

3.2 Python module

You can import the module as well

import word_ladder

7

word_ladder Documentation, Release 0.0.1

8 Chapter 3. Getting started

CHAPTER 4

Running the tests

You will have to use nose to run the tests

$ nosetests

9

word_ladder Documentation, Release 0.0.1

10 Chapter 4. Running the tests

CHAPTER 5

References

• https://bradfieldcs.com/algos/graphs/word-ladder/

11

word_ladder Documentation, Release 0.0.1

12 Chapter 5. References

CHAPTER 6

word_ladder CLI

Installing this package provides a command line interface which one is better describer with its CLI help

$ word_ladder -h

will output

Word ladder

Usage:word_ladder from <from> using <dict_file> [-a]word_ladder from <from> to <to> using <dict_file> [-a]word_ladder -h | --helpword_ladder -v | --version

Subcommands:from The initial wordto The word to stop [Optional]

Options:-a, --all-paths Print all paths-h, --help Show this screen-v, --version Show version

Examples:word_ladder from word1 using /english.dictword_ladder from word1 using /english.dict --all-pathsword_ladder from word1 to word2 using /english.dict -a

13

word_ladder Documentation, Release 0.0.1

14 Chapter 6. word_ladder CLI

CHAPTER 7

word_ladder package

7.1 Submodules

7.2 word_ladder.errors module

exception word_ladder.errors.WordsNotDefinedBases: Exception

7.3 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 withdifferent 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

15

word_ladder Documentation, Release 0.0.1

• 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 differ-ent lengths

Raises WordsNotDefined – If any of the words is None

Returns With the word’s path or None

Return type (list)

graphHolds 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)

16 Chapter 7. word_ladder package

Python Module Index

wword_ladder.errors, 15word_ladder.word_ladder, 15

17

word_ladder Documentation, Release 0.0.1

18 Python Module Index

Index

Bbuild() (word_ladder.word_ladder.Graph method), 15

Ffind_path() (word_ladder.word_ladder.WordLadder

method), 16

GGraph (class in word_ladder.word_ladder), 15graph (word_ladder.word_ladder.WordLadder attribute),

16

Wword_ladder.errors (module), 15word_ladder.word_ladder (module), 15WordLadder (class in word_ladder.word_ladder), 15words_has_same_length()

(word_ladder.word_ladder.WordLaddermethod), 16

WordsNotDefined, 15

19