实验吧编程题:字典

python编程实现

原题:包含ctf的单词的总字符有多少?

代码:

1 list = []
2 for line in open('dictionary/dictionary.txt', 'r'):  
3     rs = line.replace('\n', '')  
4     list.append(rs)
5 sum = 0
6 for i in list:
7     if "ctf" in i:
8         sum += len(i)
9 print sum

不得不说文件很大,刚开始试着读取的时候读了有3分钟,但是整个程序的运行速度还是很快的。

原文:博客园 hell0_w

 

posted @ 2017-09-24 18:08  hell0_w  阅读(255)  评论(0编辑  收藏  举报