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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -