src.ch02 package

Submodules

src.ch02.c1_recursive_palindrome module

Recursively determine if a word is a palindrome.

src.ch02.c1_recursive_palindrome.main(word: str = None) → None[source]

Demonstrate the recursive palindrome tester.

This is only supposed to be a demo, but coverage necessitates excessiveness.

Parameters

word (str) – Word to test if it is a palindrome.

Returns

None. Identifies word as a palindrome.

src.ch02.c1_recursive_palindrome.recursive_ispalindrome(word: str) → bool[source]

Recursively check if a word is a palindrome.

Parameters

word (str) – String to check palindrome-ness.

Returns

True if the word is a palindrome, False otherwise.

Raises

TypeError – If word is not a string.

src.ch02.p1_cleanup_dictionary module

Cleanup word dictionary.

Various functions for cleaning up a word dictionary.

src.ch02.p1_cleanup_dictionary.APPROVED_WORDS

Words that should always appear in a word dictionary.

Type

list

src.ch02.p1_cleanup_dictionary.cleanup_dict(filepath: str) → list[source]

Wrap read_from_file and cleanup_list.

Passes given filepath through read_from_file() to get a list of words, then cleanup_list() to remove single letter words.

Parameters

filepath (str) – String with path to word dictionary file.

Returns

List with words as elements excluding single letter words.

src.ch02.p1_cleanup_dictionary.cleanup_list(word_list: list) → list[source]

Cleanup word list.

Remove single letter words from a list of words.

Parameters

word_list (list) – List with words as elements.

Returns

List with words as elements excluding single letter words.

Raises

IndexError – If word_list is empty.

src.ch02.p1_cleanup_dictionary.cleanup_list_more(word_list: list) → list[source]

Cleanup word list even more.

First, remove words with apostrophes, double letter words, duplicates, and words with letters not in string.ascii_lowercase from a list of words. Then, add APPROVED_WORDS back into list. Finally, sort list.

Parameters

word_list (list) – List with words as elements.

Returns

Sorted list with words as elements excluding cleaned words and APPROVED_WORDS added.

Raises

IndexError – If word_list is empty.

src.ch02.p1_cleanup_dictionary.main()[source]

Demonstrate cleanup dictionary.

Module contents

Chapter 2.

src.ch02.DICTIONARY_FILE_PATH

String with path to Ubuntu 18.04.2’s American English dictionary file.

Type

str

src.ch02.CLEANUP_LIST_ERROR

String with IndexError for Cleanup Dictionary cleanup_list().

Type

str

src.ch02.RECURSIVE_ISPALINDROME_ERROR

String with TypeError for Recursive Palindrome recursive_ispalindrome().

Type

str