python challenge question (string manipulation)
johnjsal at NOSPAMgmail.com
Wed Mar 29 21:27:13 CEST 2006
Ok, for those who have gotten as far as level 2 (don't laugh!), I have a
question. I did the translation as such:
alphabet = string.lowercase[:26]
code = string.lowercase[2:26] + 'ab'
clue = "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."
trans = string.maketrans(alphabet, code)
clue = clue.translate(trans)
It works, but is there a better way to shift the letters of the alphabet
for 'code'? I remember a method that did this for lists, I think, but I
can't remember what it was or if it worked for strings.
More information about the Python-list