Deleting specific characters from a string

Behrang Dadsetan ben at dadsetan.com
Thu Jul 10 02:57:36 EDT 2003


Jeff Hinrichs wrote:
> def stringReplace(s,c):
> """Remove any occurrences of characters in c, from string s
>     s - string to be filtered, c - characters to filter"""
>     for a in c:
>         s = s.replace(a,'')
>     return s
> 
> It wins also by being easy to understand, no filter or lambda.  Not that I
> have anything against filter or lambda, but when the speediest method is the
> most readable, that solution is definitely the Pythonic champ. :)

Well I really had nothing against the filter, but this solution looks 
also acceptable.

Thanks.
Ben.





More information about the Python-list mailing list