第三关的谜面是:
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'