word to digit module

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

  1. 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
    #1
    1. Advertising

  2. Gurpreet Sachdeva

    M.E.Farmer Guest

    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
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fangs
    Replies:
    3
    Views:
    9,766
    darshana
    Oct 26, 2008
  2. championsleeper
    Replies:
    6
    Views:
    990
    championsleeper
    Apr 6, 2004
  3. Curt_C [MVP]

    Re: Generating 8 digit unique ID

    Curt_C [MVP], Apr 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    472
    Curt_C [MVP]
    Apr 20, 2004
  4. Stephen Thorne

    Re: word to digit module

    Stephen Thorne, Dec 22, 2004, in forum: Python
    Replies:
    5
    Views:
    331
    John Machin
    Dec 22, 2004
  5. April
    Replies:
    16
    Views:
    190
    Ted Zlatanov
    Jul 7, 2008
Loading...

Share This Page