translate tables versus replace

David Bear david.bear at
Thu Oct 31 23:08:50 CET 2002

I have a string that contains certain chars that I want removed.  The chars 
can be anywhere and in any order.   I initially thought of something like

string.replace(line, badchar1, '').replace(badchar2, '').replace(badchar3, 

But then I thought perhaps a translate table would work.  A translate table 
that would convert the badchars into a space might work.  I was hoping 
there was an easier way.  However my biggest concern is performance of 
successive calls to replace versus a call to translate.  Which might be 

More information about the Python-list mailing list