The maketrans
is used to map characters so that they match. First you pass a string with the characters that will be "translated", then the mapping of it, where the position of the map, corresponds to the translation of the first element of the passed string.
This can be seen in the following example:
from string import maketrans
char_a_ser_convertida = 'abcdef'
mapa_de_traducao = 'ABCDEF'
traducao = maketrans(char_a_ser_convertida, mapa_de_traducao)
str = 'abcg'
print str.translate(traducao)
The output of that print
will be:
ABCg
Note that he only converted the mapped characters to their corresponding characters on the map. Basically what it does is translate a character to a matching element in the mapping string.
It makes sense then. If I create a map with the whole alphabet, can solve the problem in a very simple way... Thanks!
– Gabe