On Sun, Feb 24, 2013 at 2:26 PM, Sudo Nohup <[email protected]> wrote:
> Thanks very much!! > > I learnt a lot from you kind reply. Not only is it about the question > itself, but also about how to ask a question in a mailing list.(Sorry that > it is the first time for me to ask questions in a mailing list). > > The question comes from a riddle of the PythonChallenge website( > http://www.pythonchallenge.com/pc/def/map.html). > > Now I write the code as the following, > > mystring = "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." > temp = [ chr ( (ord(char)-ord('a')+2)%26 +ord('a')) if > (ord(char)>=ord('a') and ord(char)<=ord('z')) else char for char in > mystring ] > result = "".join(temp) > print result > > OR > > mystring = "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." > result = [] > for char in mystring: > if(ord(char)>=ord('a') and ord(char)<=ord('z')): > char = chr ( (ord(char)-ord('a')+2)%26 +ord('a')) > result.append(char) > result = "".join(result) > print result > > Thanks, > James > > > > Hi James, for this riddle, look for the translate() method. Have fun nwith the challenges. Jos
_______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
