Micro-PEP: str.translate(None) to mean identity translation

M.E.Farmer mefjr75 at hotmail.com
Sat Apr 30 00:27:18 EDT 2005


Bengt Richter wrote:
> Just thought None as the first argument would be both handy and
mnemonic,
> signifying no translation, but allowing easy expression of deleting
characters,
> e.g.,
>
>    s = s.translate(None, 'badcharshere')
>
> Regards,
> Bengt Richter

What's wrong with :

s = s.replace('badchars', "")

It seems obvious to replace a char ( to me anyway ) with a blank
string, rather than to 'translate' it to None.
I am sure you have a reason what am I missing ?
M.E.Farmer




More information about the Python-list mailing list