Python Challenge level 02
来源:互联网 发布:怎么查看微信数据 编辑:程序博客网 时间:2024/04/30 04:43
进入:http://www.pythonchallenge.com/pc/def/ocr.html 页面,图片下方有句提示“recognize the characters. maybe they are in the book,but MAYBE they are in the page source.”,这句话告诉我们要找的字符可能在图片的书上,或者在页面源码中。所以我们想到去查看该页面的源代码。
<!--find rare characters in the mess below:--><!--%%$@_$^__#)^)&!_+]!*@&^}@[@%]()%+$&[(_@%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{_@#_^{*...-->
发现源代码中有一大段形如上面被注释掉的字符,现在要做的工作就是从这一大段字符中找出出现次数少的字符。那怎么知道在这些一大段杂乱的字符串中,那些字符是出现次数少的呢?硬办法就是把所以字符出现的次数统计一遍。
代码如下:
data = """..."""count = {}for i in data: if i in count: count[i] += 1 else: count[i] = 1for key, val in count.items(): print "%s: %d" % (key, val)
好了现在统计出所有字符出现的次数了:
: 1219
!: 6079
#: 6115
%: 6104
$: 6046
&: 6043
): 6186
(: 6154
+: 6066
*: 6034
@: 6157
[: 6108
]: 6152
_: 6112
^: 6030
a: 1
e: 1
i: 1
l: 1
q: 1
u: 1
t: 1
y: 1
{: 6046
}: 6105
出现次数最少的有8个字符:a, e, i, l, q, u, t, y。但是这8个字母顺序是按ASCII 码排列的,不是一个具有意义的单词。但做到这里至少我们知道,这堆杂乱的字符串中出现次数最少的几个小写字母。然后,可以用正则表达把这几个字母找出来,并且按字母在字符中先后出现的顺序打印出来。
代码如下:
import redata = """..."""print "".join(re.findall("[a-z]", data))
输出结果:equality
这个就是我们要找的字符串了,将它到URL地址中替换成:http://www.pythonchallenge.com/pc/def/equality.html,进入下一题。
- Python Challenge level 02
- Python challenge - level 10
- Python Challenge level 0
- Python Challenge level 01
- Python Challenge level 03
- The Python Challenge Level 0-1 Solutions
- The Python Challenge Level-2 Solution
- The Python Challenge Level-6 Solution
- The Python Challenge Level-3 Solution
- The Python Challenge Level-4 Solution
- The Python Challenge Level-5 Solution
- The Python Challenge Level-7 Solution
- The Python Challenge Level-8 Solution
- The Python Challenge Level 9-10 Solutions
- The Python Challenge Level-11 Solution
- Python Challenge 02 Solution
- python challenge
- Python Challenge
- 从程序员到项目经理(18):不要试图和下属做朋友
- Android Intent组件使用
- 从程序员到项目经理(19):想改变任何人都是徒劳的
- 黑马程序员-javaBean内省 泛型 类加载器 动态代理
- 从程序员到项目经理(20):让员工为目标而干活
- Python Challenge level 02
- 同步/异步与阻塞/非阻塞的区别
- CentOS之httpd与apache安装区别
- UPnP基本原理以及在NAT中的应用
- synergy XP & ubuntu共用一套键盘鼠标,问题解决
- MQ、JMS以及ActiveMQ
- 关于mysql存储过程的definer的问题1
- vb调用webservice的另一种方式
- Python基础