superstring.py icon indicating copy to clipboard operation
superstring.py copied to clipboard

Feature request: replace

Open endrebak opened this issue 4 years ago • 3 comments

>>> "hi".replace("h", "H")
Hi

Would be neat if it could take a dict so this worked:

>>> "hi".replace({"h": "i", "i": "h"})
ih

Or a regex (see pandas.Series.str for inspiration?):

"hi".replace("h|i", "NYAN")
NYANNYAN

endrebak avatar Mar 25 '20 07:03 endrebak

Hello @endrebak, thank you, I will start working on this for the as soon as possible. I will check also that pandas.Series.str.

btwael avatar Mar 25 '20 08:03 btwael

pervert request... how about sticking to standard string api and implementing extra stuff in a separate class/whatever? And creating a PR for Python to include your optimizations for standard string

kamikaze avatar Apr 07 '20 20:04 kamikaze

Or the PR could improve the API too if it is backwards compatible. The second suggestion is but the third isn’t.

This is backwards compatible:

import re
pat = re.compile(“h|i”)
"hi".replace(pat, "NYAN")
NYANNYAN

endrebak avatar Apr 07 '20 20:04 endrebak