Parse Numbers Written in English

This function, when passed a string such as “six hundred twenty two,” should return the numerical value. It should handle numbers up to 999,999,999.

This function ignores the word “and” anywhere it appears in the input string.

Source Code

						1.     """ Define a dictionary mapping between English words
 2.         and the corresponding numbers.
 3.     """
 4.     digitmap = {
 5.         "zero" : 0,
 6.         "one" : 1,
 7.         "two" : 2,
 8.         "three" : 3,
 9.         "four" : 4,
10.         "five" : 5,
11.         "six" : 6,
12.         "seven" : 7,
13.         "eight" : 8,
14.         "nine" : 9,
15.         "ten" : 10,
16.         "eleven" : 11,
17.         "twelve" : 12,
18.         "thirteen" : 13,
19.         "fourteen" : 14,
20. "fifteen" ...

Get Find the Bug A Book of Incorrect Programs now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.