Removing Space and "-" from a string

Terry Reedy tjreedy at udel.edu
Wed May 21 15:38:27 EDT 2008


"Paul Hankin" <paul.hankin at gmail.com> wrote in message 
news:9d9dadfe-3f91-44a6-8b1b-50fe8003046d at e39g2000hsf.googlegroups.com...
On May 20, 5:02 pm, "Ahmed, Shakir" <shah... at sfwmd.gov> wrote:
> I have thousands of records in MS Access database table, which records I
> am fetching using python script. One of the columns having string like
> '8 58-2155-58'
>
> Desired output: '858215558'

|def cleanup(s):
|    return filter(lambda x: x not in ' -', s)

Or
>>> s='8 58-2155-58'
>>> t=str.maketrans('','',' -')
>>> s.translate(t)
'858215558'







More information about the Python-list mailing list