Wordize¶
You are required to deliver the following function in the module words (file words.py):
- wordize_digits(digit_words, text)¶
such that
- given
- returns a
strlike 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.