这一关谜面是:“确认字母,它们可能在书中,但也可能在PageSource中。”
PageSource应该是指页面的源代码,查看后在最后面发现如下的提示:
<!--
find rare characters in the mess below:
-->紧跟着的就是一代段的字符串。看来谜底就是找出这些字符串中的字母。
我是先把这些字符串粘贴到一个文本中在处理的:
f = open("data.txt","r")
dd = "abcdefghijklmnopqrstuvwxyz"
words = ""
for i in f:
for j in i:
if j in dd:
words += j
print words
f.close()结果为:
equality
==========================分割线==========================
摘录几个答案:
>>> import string
>>> filter(lambda x: x in string.letters, text)
'equality'import urllib
f=urllib.urlopen('http://www.pythonchallenge.com/pc/def/ocr.html')
txt=f.read()
for c in '!@#$%^&*()+_-{}[]\n':
txt = txt.replace(c,"")
print txtimport urllib
# I'm sorry PEP8
s = urllib.urlopen('http://www.pythonchallenge.com/pc/def/ocr.html').read().split('<!--')[-1].replace('-->', '')
print ''.join(filter(lambda x: x.isalnum(), s))
本文介绍了一种从复杂网页源代码中提取特定字母的方法,通过Python编程实现了字符串过滤,最终找到了隐藏的单词“equality”。文章展示了使用不同Python库进行文本处理的过程。

被折叠的 条评论
为什么被折叠?



