Wordize List

You are required to deliver the following function in the module words (file words.py):

wordize_list(digit_words, parL)

such that

given
  • digit_words, a str of characters with the name of each digit in increasing order, separated by ‘,’. Ex. 'zero,one,two,three,four,five,six,seven,eight,nine'.

  • parL, a list of str with arbritary texts.

modifies parL such that all digits in all strings in parL are wordized.

For example:


>>> dwords = 'zero,one,two,three,four,five,six,seven,eight,nine'
>>> wordsL = ['number 2', '2 or 3 times', '1, 2 and 3', '2 plus 3 equals 5']
>>> wordize_list(dwords, wordsL)
>>> wordsL
['number two', 'two or three times', 'one, two and three', 'two plus three equals five']

Additional doctests for validation are available in the wordize_list.test file.

Tip

Find bellow the specification of the function wordize_digits() of a string that should be familiar to you. Its implementation can be written/copied/imported and used to your convenience.


Find herewith the specification of the (hereauxiliar) wordize_digits function:

wordize_digits(digit_words, text)

such that

given
  • digit_words, a str of characters with the word for each digit (10), in increasing order, separated by ‘,’. For instance 'zero,one,two,three,four,five,six,seven,eight,nine'.

  • text, any str of characters

returns a str like text where
  • all digits has been replaced by the word denoting that digit followed by the digit between parenthesis

  • letters remain the same

  • characters that not letters or digits are removed except dot ('.'), coma (,), space (' '), semicolon (';') and colon (':') that remain the same.

For example:


>>> dwords = 'zero,one,two,three,four,five,six,seven,eight,nine'
>>> s = 'The order includes 3 beers, 2 coctails and 5 shots.'
>>> wordize_digits(dwords, s)
'The order includes three(3) beers, two(2) coctails and five(5) shots.'

Tip

The digit words can be useful to get the word of a given digit: use the number represented by the digit as the index over the list resulting from spliting the digit_words string by ','. This is not the only way though but is very convenient.

Additional doctests for validation are available in the wordize_digits.test file.