I would like to write the following code:
import string frm = b'acdefhnoprstuw' to = 'אקדיפהנופרסתאו' trans_table = string.maketrans(frm, to) hebrew_phrase = 'fear cuts deeper than swords'.translate(trans_table)
The above code does not work, because the to parameter for string.maketrans(frm, to) should be a byte sequence, not a string. The problem is that byte sequences can only contain ASCII alphabetic characters. Therefore, I cannot make a transformation that translates English strings to Hebrew strings. The reason is because string.maketrans() is extracting a byte object.
Is there an elegant way to use string.maketrans() and translate() functions (or equivalent functions that work with unicode) for my task?
snakile
source share