import re#导入正则表达式模块
import csv
def stats_text_en():
found = {}#建立空的字典
a= text.lower()
a=re.sub("[^\\u0061-\u007a]", " ", a)#小写字母unicode范围,筛选英文
a=a.split()#指定分隔符对字符串进行切片
for i in a:
if i in found:
found[i]+=1
else:
found[i]=0
found[i]+=1
txt=sorted(found.items(),key=lambda x:x[1],reverse=True)
print(txt)
with open('','r') as f:
text = f.read()
with open('status.csv','w',encoding=('UTF-8-sig'),newline='') as f:
csv_writer = csv.writer(f)
csv_writer.writerow(['单词','词频','词义'])
for i in txt:
word= str(i[0])
frequency= str(i[1])
csv_writer.writerow([word,frequency])
英文高频词统计并打印
最新推荐文章于 2023-03-25 15:58:15 发布