zoukankan      html  css  js  c++  java
  • 英文字频统计

    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])
  • 相关阅读:
    java入门最好的一套书
    【转载】vim的E492错误
    SESSION保存到数据库中,然后从数据库中读取
    django教程
    用vim写python代码的两个关键设置
    HTTP/1.1中文版
    SQL基础教程
    简单清晰的HTML教程
    vim中如何按一个键就保存文件
    【转载】Vim操作
  • 原文地址:https://www.cnblogs.com/yh5788lz/p/8652834.html
Copyright © 2011-2022 走看看