[Tutor] Python Challange - ord chr incrementing alphabet
adam.jtm30 at gmail.com
Tue Jun 20 15:35:19 CEST 2006
On 20/06/06, Paul D. Kraus <paul.kraus at gmail.com> wrote:
> I just started doing the python challenges and was doing the one where the
> hint is 3 letters each shifted two places to the right.
> No big deal just ord / chr and some tests to handle looping past z.
> I got my answer. Then reading the solutions i see that they suggest that
> the best way would be to use string.maketrans()
> I just can't figure this out. What does this do and how would it help with
> this problem?
Here's what I came up with for that challenge:
t = string.maketrans("abcdefghijklmnopqrstuvwxyz",
s = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc
dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle.
sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
string.maketrans() translates the letters with the same index so a=c b=d
etc. s.translate needs a translation table which is what string.maketrans()
returns so you just use s.translate with t the translation table and it
gives you the proper translation.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor