word to digit module

G

Gurpreet Sachdeva

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

Thanks and Regards,
GSS
 
M

M.E.Farmer

Gurpreet said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top