# word to digit module

Discussion in 'Python' started by Gurpreet Sachdeva, Dec 22, 2004.

1. ### Gurpreet SachdevaGuest

Is there any module available that converts word like 'one', 'two',
'three' to corresponding digits 1, 2, 3??

Thanks and Regards,
GSS

Gurpreet Sachdeva, Dec 22, 2004

2. ### M.E.FarmerGuest

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

M.E.Farmer, Dec 22, 2004