word to digit module

M.E.Farmer mefjr75 at hotmail.com
Wed Dec 22 06:28:21 CET 2004


Gurpreet Sachdeva wrote:
> Is there any module available that converts word like 'one', 'two',
> 'three' to corresponding digits 1, 2, 3??
>
> Thanks and Regards,
> GSS


Hello,
This is not a module but is a way to do it
Hope this helps you.
################################################
# lookup example
numbers = {'zero':0,
'one':1,
'two':2,
'three':3,
'four':4,
'five':5,
'six':6,
'seven':7,
'eight':8,
'nine':9}

def getNumber(numname, numbers):
return numbers.get(numname.lower(), 'error')

print getNumber('OnE' , numbers)
print getNumber('siX' , numbers)
print getNumber('fOur' , numbers)
print getNumber('nine' , numbers)
print getNumber('SEven' , numbers)
#################################################

M.E.Farmer




More information about the Python-list mailing list