We had to translate the relevant characters:
k ->m
o -> q
e -> g
---------------------------------------
#!/usr/bin/python
import string
str1 = "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"
str2 = string.maketrans(string.ascii_lowercase, string.ascii_lowercase[2:] + string.ascii_lowercase[:2])
print str1.translate(str2)
-------------------------------------
Answer = map => ocr
challenge 3:
http://www.pythonchallenge.com/pc/def/ocr.html
Learning:
string module: import string
string.ascii_lowercase => 'a-z' characters string
mapping = string.maketrans(str1, str2) => creates the mapping for str1 chars to str2 chars
s1.translate(mapping) => returns translated string
k ->m
o -> q
e -> g
---------------------------------------
#!/usr/bin/python
import string
str1 = "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"
str2 = string.maketrans(string.ascii_lowercase, string.ascii_lowercase[2:] + string.ascii_lowercase[:2])
print str1.translate(str2)
-------------------------------------
Answer = map => ocr
challenge 3:
http://www.pythonchallenge.com/pc/def/ocr.html
Learning:
string module: import string
string.ascii_lowercase => 'a-z' characters string
mapping = string.maketrans(str1, str2) => creates the mapping for str1 chars to str2 chars
s1.translate(mapping) => returns translated string
No comments:
Post a Comment