您的位置:首页 > 编程语言 > Python开发

PythonChallenge 挑战之路 Level-3

2013-07-30 19:07 363 查看
第三关的谜面是:

One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.

大概意思就是每一个小写字母的两边都有且只有3个大写字母,也就是如oXXXaXXXo的形式中,a就是需要找出的小写字母。

同样从网页源码里找到目标文本,代码如下:

import urllib
import re

text = urllib.urlopen('http://www.pythonchallenge.com/pc/def/equality.html').read().split('<!--')[-1].replace('-->', '')
print "".join(re.findall('[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]', text))结果为:
linkedlist

替换URL后提示使用linkedlist.php,顺利进入下一关:)

=================分割线===================

这个方法挺有意思:

>>> import string
>>> code = """
... <copy and paste>
... """.replace("\n", "")
>>> word = ""
>>> for i in range(len(code) - 8):
... if [c for c in code[i:i+9] if c in string.lowercase] == [code[i], code[i+4], code[i+8]]:
... word += code[i+4]
...
>>> word
'linkedlist'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: