There's got to be an easy way to do this
Tim Peters
tim at digicool.com
Thu Jul 5 14:27:20 EDT 2001
[Lindstrom Greg]
> I am reading in a phone number field and would like to throw away
> everything except the digits.
Simplest:
>>> def isdigit(c):
... return c in "0123456789"
...
>>> filter(isdigit, "(555) 333.2221")
'5553332221'
>>>
Fastest: Read the docs for string.translate(); set it to do identity (i.e.,
no) translation, and pass everthing *except* digits in its optional third
("delete these") argument.
More information about the Python-list
mailing list