英文字频统计

Can it really be sixty-two years ago that I first saw you?
It is truly a lifetime, I know. But as I gaze into your eyes now, it seems like only yesterday that I first saw you, in that small café in Hanover Square.
From the moment I saw you smile, as you opened the door for that young mother and her newborn baby. I knew. I knew that I wanted to share the rest of my life with you.
I still think of how foolish I must have looked, as I gazed at you, that first time. I remember watching you intently, as you took off your hat and loosely shook your short dark hair with your fingers. I felt myself becoming immersed in your every detail, as you placed your hat on the table and cupped your hands around the hot cup of tea, gently blowing the steam away with your pouted lips.

将分隔符替换为空格
symbol=[".",",","'",'"']
for i in range(len(symbol)):
    str=str.replace(symbol[i]," ")

将所有大写转换为小写
str=str.lower()

生成单词列表
str=str.split()

d=dict(zip())
生成词频统计
for key in str:
    d[key]=str.count(key)

排除语法型词汇,代词、冠词、连词
str1=['a','an','more','for','is','of','to','from','or','that','if','the','were','in','s','not','can','get','could','might','up','and','this','t']
for i in str1:
    del d[i]

排序
d=sorted(d.items(),key=lambda e:e[1],reverse=True)

输出词频最大TOP10
for i in range(10):
    print(d[i])
原文地址:https://www.cnblogs.com/yh5788lz/p/8652834.html