1. 程式人生 > >實驗吧編程題:字典

實驗吧編程題:字典

replace cti 分鐘 nbsp python line open pytho ict

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分鐘,但是整個程序的運行速度還是很快的。

實驗吧編程題:字典