Removing Space and "-" from a string

Paul Hankin paul.hankin at gmail.com
Wed May 21 02:47:14 EDT 2008


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'
>
> I want to remove any spaces between string and any dashes between
> strings. I could do it in access manually but want to do from python
> script

'filter' returns a string if it's argument is a string, so works
nicely here.

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

--
Paul Hankin



More information about the Python-list mailing list