Eliminate a list of characters from a string?

Max maxx at easynews.com
Thu Mar 27 20:07:36 CET 2003


What is the simplest method (that does not perform too poorly) for eliminating
any of a list of characters from a string. Currently, I ahev a script that used
multiple string.replace statements. In other words, if I have the string
'A1B2C3' and want to eliminate the numbers leaving 'ABC' I could use:

S1='A1B2C3'
S2=STRING.REPLACE(S1,'1','')
S2=STRING.REPLACE(S2,'2','')
S2=STRING.REPLACE(S2,'3','')

However, if the list of eliminated characters is long, it seems a bit
inefficient.

TIA!




More information about the Python-list mailing list