Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > word to digit module

Reply
Thread Tools

word to digit module

 
 
Gurpreet Sachdeva
Guest
Posts: n/a
 
      12-22-2004
Is there any module available that converts word like 'one', 'two',
'three' to corresponding digits 1, 2, 3??

Thanks and Regards,
GSS
 
Reply With Quote
 
 
 
 
M.E.Farmer
Guest
Posts: n/a
 
      12-22-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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(8-bit binary to two digit bcd) or (8-bit binary to two digit seven segment) Fangs VHDL 3 10-26-2008 06:41 AM
change a single digit to corresponding English word April Perl Misc 16 07-07-2008 08:51 PM
Re: module docstring, documentation,anything? please note is the module type/object NOT some module Maric Michaud Python 0 06-24-2006 12:42 PM
Re: word to digit module Stephen Thorne Python 5 12-22-2004 11:15 PM
match three digit number using regular expression championsleeper Perl 6 04-06-2004 08:54 PM



Advertisments