(个人项目)英语文章词频统计

因为刚刚接触python,暂时只能独立完成字母出现的次数,单词的词频统计会在一周的学习后补充上。

需求分析:1:能统计英文字数长短不一的文章。

              2:显示整篇文章26个英语字母出现的次数。

              3:以字母表顺序排列出来。

代码如下:

lines=open('D:\pdb\a').readlines()

print(lines)

for each_item in lines:

each_item=each_item.lower()

x=list(each_item)

content={}

for each in x:

if each==''or each==','or each=='.' or each=='!'or each==';'or each=='-'or each=='%' or each=='$'or each==' ':

continue

if each not in content.keys():

content[each]=0

content[each]+=1

y=sorted(content.items(),key=ambda item:item[0])  

print(y)

开学之后第一次接触Python这个新语言,对其语句的使用及其格式还不够熟练,会尽快掌握。对其生成大字典的功能及通过对应字典里的key,及value值进行序列的排序及其添加的功能有所掌握。

原文地址:https://www.cnblogs.com/yangyuning/p/5845786.html