Better way to replace/remove characters in a list of strings.

Chris Brat chrisBrat at gmail.com
Mon Sep 4 14:51:54 CEST 2006


Thanks, thats exactly what I was looking for - very neat.


George Sakkis wrote:
> Philipp Pagel wrote:
>
> > Chris Brat <chrisBrat at gmail.com> wrote:
> > > Is there a better way to replace/remove characters (specifically ' and
> > > " characters in my case, but it could be anything) in strings in a
> > > list, than this example to replace 'a' with 'b':
> >
> > x = map(lambda foo: foo.replace('a', 'b'), x)
>
> Or more pythonically:
> 
> x = [s.replace('a', 'b') for s in x]
> 
> George




More information about the Python-list mailing list