superstring.py
superstring.py copied to clipboard
Feature request: replace
>>> "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
Hello @endrebak, thank you, I will start working on this for the as soon as possible. I will check also that pandas.Series.str
.
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
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