Open In App

Python text2digits Module

Last Updated : 21 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

A text2digits module is that library of python which helps you to convert text numbers into digits which are present in a string .You can find this useful in Alexa/Lex operations to convert audio to text and have to convert the text to digits.

Installing Library

This module does not come built-in with Python. You need to install it externally. To install this module type the below command in the terminal.

pip install text2digits

Example :




# Importing text2digits function  
  
# From text2digits Library  
  
from text2digits import text2digits
  
# we have to create a object of this function
  
a = text2digits.Text2Digits()
  
from text2digits import text2digits
a = text2digits.Text2Digits()
  
ans = a.convert("twenty ten and thirty six")
print(ans)
  
ans = a.convert("I was born in nineteen ninety nine")
print(ans)
  
ans = a.convert("I am twenty ")
print(ans)
  
ans = a.convert("one thousand and six hundred and sixty six")
print(ans)
  
ans = a.convert("I was born in nineteen eighty eight and am  thirty two years old !")
print(ans)
  
ans = a.convert("sixty billion forty million twenty thousand four hundred six")
print(ans)
  
ans = a.convert("I am thirty six years old with a child who is four.")
print(ans)
  
ans = a.convert("one is not divisible by zero")
print(ans)
  
ans = a.convert("Sixteen and seven" )
print(ans)
  
ans = a.convert("one two three four five six seven eight nine")
print(ans)
type(ans)


Output :

2010 and 36
I was born in 19 ninetynine
I am 20 
1666
I was born in 1988 and am  32 years old !
60040020406
I am 36 years old with a child who is 4.
1 is not divisible by 0
16 and 7
123456789
str

Note : text2digits always takes string as input otherwise it will raise a SyntaxError .


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads