python入门教程至此已学习完毕,下面是结业脚本:(一部分是书里的源码,一部分是自己加的练习题)
#写一个文本统计的脚本:计算并打印有关文本文件的统计数据,包括文件里包含多少个字符、行、单词数,以及前10个出现次数最多的单词按顺序排列
import time
keep=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ','-',"'"]
stop_words=['the','and','i','to','of','a','you','my','that','in','she','he','her','his','it','be','was','had']
def normalize(s):
result=''
for c in s.lower():
if c in keep:
result+=c
re