Is there a way to convert number words to Integers?

前端 未结 16 2010
北恋
北恋 2020-11-22 06:14

I need to convert one into 1, two into 2 and so on.

Is there a way to do this with a library or a class or anythi

16条回答
  •  太阳男子
    2020-11-22 06:47

    Here's the trivial case approach:

    >>> number = {'one':1,
    ...           'two':2,
    ...           'three':3,}
    >>> 
    >>> number['two']
    2
    

    Or are you looking for something that can handle "twelve thousand, one hundred seventy-two"?

提交回复
热议问题