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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.