xxxxxxxxxx
txt = "Good night Sam!"
x = "mSa"
y = "eJo"
z = "odnght"
mytable = txt.maketrans(x, y, z)
print(txt.translate(mytable))
xxxxxxxxxx
The translate() method returns a string where some specified characters
are replaced with the character described in a dictionary.
Syntax : string.translate(table)
example :
# use a dictionary with ascii codes to replace 83 (S) with 84 (T):
mydict = {83: 84}
txt = "Hello Samer!"
print(txt.translate(mydict)) # output is "Hello Tamer!"