码迷,mamicode.com
首页 > 编程语言 > 详细

Python Challenge

时间:2015-07-10 11:01:35      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

0. 

1 print 2**38
2 ##apply the result to the url

1. 看图是要right shift两位, 切片即可。

技术分享
 1 import string
 2 
 3 intab = string.ascii_lowercase
 4 outtab = intab[2:] + intab[:2]
 5 trans_table = string.maketrans(intab, outtab)
 6 
 7 s = """
 8     g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle
 9     gr gl zw fylb gq glcddgagclr ylb rfyr‘q ufw rfgq rcvr gq qm jmle.
10     sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."""
11 
12 print s.translate(trans_table)
13 print map.translate(trans_table)
14 
15 ##The result is
16 ##
17 ##    i hope you didnt translate it by hand. thats what computers are for. doing
18 ##    it in by hand is inefficient and that‘s why this text is so long.
19 ##    using string.maketrans() is recommended. now apply on the url.
20 ##ocr
21 
22 ##apply ocr to the url
View Code

2. 寻找出现次数少的character

技术分享
 1 import string
 2 
 3 result = {}
 4 text = open(003help.txt).read()
 5 for ch in text:
 6     result[ch] = result.get(ch, 0) + 1
 7 
 8 print result
 9 print ‘‘.join(ch for ch in result if result[ch]==1)
10 s = []
11 for i in text:
12     if i in string.ascii_lowercase:
13         s.append(i)
14 print ‘‘.join(s)
15 
16 ##apply ‘equality‘ to the url
View Code

3. One small letter, surrounded by EXACTLY three big bodyguards on each of its sides. 正则表达式!

技术分享
import re

pattern = re.compile([^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z])
text = open(004help.txt).read()

t = re.findall(pattern, text)
print ‘‘.join(t)

##apply to the url
View Code

stay tuned...

Python Challenge

标签:

原文地址:http://www.cnblogs.com/FARAMIR/p/4634809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!