See string.translate
import string
"abc".translate(string.maketrans("abc", "def")) # => "def"
Note the doc's comments about subtleties in the translation of unicode strings.
And for Python 3, you can use directly:
str.translate(str.maketrans("abc", "def"))
Edit: Since tr
is a bit more advanced, also consider using re.sub
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…