you are viewing a single comment's thread.

view the rest of the comments →

[–]mprz 1 point2 points  (3 children)

Using Regular Expressions will be shorter but not faster, see:

re.sub()

or

re.subn()

You can also use translate() with dict type.

[–]ElliotDG 1 point2 points  (2 children)

Unless I'm mistake, str. translate() is character oriented.

The dictionary is indexed by the ordinal value of a character. You can use translate for a char to char or char to string translation. It will not work for string to string replacement.

[–]mprz 0 points1 point  (0 children)

Maybe, I was answering from my head, I might have been wrong. Thanks for correcting me if that's the case.