regex - Removing many types of chars from a Python string -
i have string x , wish remove semicolons, periods, commas, colons, etc, in 1 go. there way doesn't require big chain of .replace(somechar,"") calls?
you can use translate method first argument of none:
string2 = string1.translate(none, ";.,:") alternatively, can use filter function:
string2 = filter(lambda x: x not in ";,.:", string1) note both of these options work non-unicode strings , in python 2.
Comments
Post a Comment