python统计文本中有多少行
1个回答
展开全部
写一个文本统计的脚本:计算并打印有关文本文件的统计数据,包括文件里包含多少个字符、行、单词数,以及前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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询