隐藏页面特效

8-3 英文统计

编写程序实现对特定英文文章(文本文件)的单词数和有效行数的统计,其中要求空行不计数;

def getText(): txt=open("english.txt","r").read() txt=txt.lower() for ch in '~!@#$%^&*()_+"{}[]|?.<>?': txt=txt.replace(ch,"") return txt hamletTxt=getText() words=hamletTxt.split() counts={} for word in words: counts[word]=counts.get(word,0)+1 items=list(counts.items()) print(len(items)) non_blank_count = 0 with open('english.txt') as infp: for line in infp: if line.strip(): non_blank_count += 1 print(non_blank_count)

 


__EOF__

本文作者往心。
本文链接https://www.cnblogs.com/lx06/p/16211062.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   往心。  阅读(58)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
历史上的今天:
2021-05-03 5.3-团队项目-每日任务-信息发送
点击右上角即可分享
微信分享提示