Python challenge_2
来源:互联网 发布:淘宝企业店铺注册条件 编辑:程序博客网 时间:2024/06/03 17:39
python challenge 上的第二题:http://www.pythonchallenge.com/pc/def/ocr.html。
这个基本上是比较好理解的,查看源代码,找寻出现次数比较少的字母。然后我就理解成找出出现次数最少的。
import ref = open(r'D:\pythonchallenge_2.txt')dict = {}for line in f: line = line.strip() l = len(line) while l: x = line[l-1] if x in dict: dict[x] += 1 else: dict[x] =1 l -= 1temp = 1000000for key,value in dict.items(): if value <temp: x = key temp = valueprint x
这段代码的输出是a。然后就不知道了,又到了查攻略的时间。发现直接把字典里面的所有数据都输出出来,无非也就下面的这几个。
!: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
有办法理解的就是那几个字母了。输进去,发现是错的,再次找攻略,知道了python中dictionary的key是无序的,并不是按照加入的顺序显示的,每个字母都只出现一次,所以,所需要的信息赢就是按照字符出现的顺序组成的字符串重新写了一份代码:
import ref = open(r'D:\pythonchallenge_2.txt')s = ''for line in f: line = line.strip() for i in line: if i.isalpha(): s += iprint s
直接就输出答案equality,下一题的链接就是:
http://www.pythonchallenge.com/pc/def/equality.html
把别人写的代码和自己写的相比较完全惨不忍睹。但是可以安慰自己,对代码还不熟悉,好好练习就好了。链接里面的同学写的很好呀。。。
http://blog.csdn.net/kosl90/article/details/7240915
0 0
- Python challenge_2
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- python
- JNI:使用RegisterNatives方法传递和使用Java自定义类
- mysql删除字段中不是数组英文字母打头的数据
- B/S和C/S的区别【转】
- python基础——数据类型
- C#调用JS QQ空间取GTK方法
- Python challenge_2
- web工程部署到tomcat报错处理
- Java Annotation 图解
- Jedis操作redis
- Java中Runnable和Thread的区别
- android资源文件中定义字符串数组
- 如何正确理解深度学习(Deep Learning)的概念
- 计算逆波兰式 Evaluate Reverse Polish Notation
- 重装mysql后无法启动的问题