I want to replace letters in a character vector by other ones, using a dictionary created with dict
, as follows
import string
trans1 = str.maketrans("abc","cda")
trans = dict(zip("abc","cda"))
out1 = "abcabc".translate(trans1)
out = "abcabc".translate(trans)
print(out1)
print(out)
The desired output is "cdacda"
What I get is
cdacda
abcabc
Now out1
is this desired output, but out
is not. I can not figure out why this is the case. How can I use the dictionary created via dict
in the translate
function? So what do I have to change if I want to use translate
with trans
?