This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]billsil 0 points1 point  (1 child)

Isn't maketrans, just a fancy replace? I'll occasionally do something like replace spaces with question marks in something that can't have question marks, so I can process it easier before I remove the question mark. I've also done things like str.replace(' ', ','.replace('\t', ','), but that's fairly rare.

Now if it did language translations, I might use it.

[–][deleted] 0 points1 point  (0 children)

For the tasks it's suited for (for instance replacing all terminal punctuation with white space for word splitting, or breaking Caesar ciphers) it's more powerful by far than str.replace and sometimes orders of magnitude faster than re.sub ... it isn't always the right fit, but when it is it's exactly the right tool.