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'
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'
相关文章推荐
- PythonChallenge 挑战之路 Level-17
- PythonChallenge 挑战之路 Level-25
- PythonChallenge 挑战之路 Level-26
- PythonChallenge 挑战之路 Level-27
- PythonChallenge 挑战之路 Level-0
- PythonChallenge 挑战之路 Level-8
- PythonChallenge 挑战之路 Level-28
- PythonChallenge 挑战之路 Level-1
- PythonChallenge 挑战之路 Level-19
- PythonChallenge 挑战之路 Level-29
- PythonChallenge 挑战之路 Level-2
- PythonChallenge 挑战之路 Level-9
- PythonChallenge 挑战之路 Level-10
- PythonChallenge 挑战之路 Level-30
- PythonChallenge 挑战之路 Level-11
- PythonChallenge 挑战之路 Level-20
- PythonChallenge 挑战之路 Level-12
- PythonChallenge 挑战之路 Level-21
- PythonChallenge 挑战之路 Level-13
- PythonChallenge 挑战之路 Level-31