Working Ninja
2016-01-11T21:47:37
Extract Only Digits From String With Python

Print all digits in a string as one integer:

>>> string = "a1b2c3"
>>> integer = int(filter(str.isdigit, string))
>>> print integer
123
>>> type(integer)
<type 'int'>

Or, if you would like a list of all digits:

>>> string = "a1b2c3"
>>> import re
>>> integer_list = re.findall('\d+', string)
>>> print integer_list
['1', '2', '3']
>>> type(integer_list)
<type 'list'>