Python challenge_1
2014-03-14 20:45
197 查看
题目是Python challenge上的第一道题:http://www.pythonchallenge.com/pc/def/map.html
首先的想法是用正则表达式搜索来分别替换三个字母。。。错了
看了攻略。知道是要做移位每个字母往后移两位:
结果:
i hope you didnt trcnslcte it dy hcnd. thcts whct computers cre for.
doing it in dy hcnd is inefficient cnd thct's why this text is so long.
using string.mcketrcns() is recommended. now cpply on the url.
大概意思能懂,但是,好像c要变成a,d要换成b才是对的。看了提示要用maketrans(),百度了一下。重新写了下代码:
答案如下:
i hope you didnt translate it by hand.
thats what computers are for. doing it in by hand is inefficient and that's why this text is so long.
using string.maketrans() is recommended. now apply on the url.
把map应用到程序中得到orc,
得到网址:http://www.pythonchallenge.com/pc/def/ocr.html
maketrans()的用法:http://hi.baidu.com/mengjingchao11/item/5e6c2afffe74491ecf9f323a
首先的想法是用正则表达式搜索来分别替换三个字母。。。错了
看了攻略。知道是要做移位每个字母往后移两位:
import re import string 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." before = 'abcdefghijklmnopqrstuvwxyz' after = 'cdefghijklmnopqrstuvwxyzab' x = zip(before,after) while x: y = x.pop() s = re.sub(y[0],y[1],s) print(s)
结果:
i hope you didnt trcnslcte it dy hcnd. thcts whct computers cre for.
doing it in dy hcnd is inefficient cnd thct's why this text is so long.
using string.mcketrcns() is recommended. now cpply on the url.
大概意思能懂,但是,好像c要变成a,d要换成b才是对的。看了提示要用maketrans(),百度了一下。重新写了下代码:
import string 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." before = 'abcdefghijklmnopqrstuvwxyz' after = 'cdefghijklmnopqrstuvwxyzab' t = string.maketrans(before,after) s = s.translate(t)
答案如下:
i hope you didnt translate it by hand.
thats what computers are for. doing it in by hand is inefficient and that's why this text is so long.
using string.maketrans() is recommended. now apply on the url.
把map应用到程序中得到orc,
得到网址:http://www.pythonchallenge.com/pc/def/ocr.html
import string 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." before = 'abcdefghijklmnopqrstuvwxyz' after = 'cdefghijklmnopqrstuvwxyzab' t = string.maketrans(before,after) s = s.translate(t)
print('map'.translate(t))
maketrans()的用法:http://hi.baidu.com/mengjingchao11/item/5e6c2afffe74491ecf9f323a
相关文章推荐
- python的可变参数
- python多返回值
- python 多变量赋值
- 002_007 Python 随机输入/输出即随机读取文件
- Python高级编程技巧
- 002_006 Python 处理文件中的每个单词
- python_numpy
- 《使用Python进行自然语言处理》学习笔记六
- Python —— 批量替换指定目录下的所有文件中指定字符串
- ctypes 载入 dll 产生的 WindowsError: [Error 126] 错误原因
- python深拷贝和浅拷贝
- Python zipfile
- python操作mysqldb
- Eclipse Python插件 PyDev
- python基本笔记
- Python笔记——(一)
- python基于mysql实现的简单队列以及跨进程锁
- Python特殊语法:filter、map、reduce、lambda
- python pack 和unpack使用
- python读配置文件