博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
9.27作业
阅读量:6951 次
发布时间:2019-06-27

本文共 1190 字,大约阅读时间需要 3 分钟。

英文字频统计

strHello='''...'''.lower()fo = open('hello.txt', 'r', encoding='utf-8')hello = fo.read()fo.close()print(hello)sep = ''',?'''for ch in sep:    strHello = strHello.replace(ch, '')    strList = strHello.split()    print(len(strList),strList)    strSet = set(strList)    exclude = {
'i', 'in', 'the''anymore'} strSet = strSet-exclude print(len(strSet),strSet) strDict = {} for hello in strSet: strDict[hello] = strList.count(hello) print(strDict.items())wcList = list(strDict.items())wcList.sort()print(strDict.items())print(wcList[:20])

运行结果

 中文字频统计(小说《装在套子里的人》

import jiebafo = open ('taozi.txt', 'r', encoding='utf-8')zhuang = fo.read ().lower ()fo.close ()print (zhuang)sep = ',。?!;:“”‘’-——<_/>'for en in sep:    zhuang = zhuang.replace (en, '')zhaung = list (jieba.cut_for_search (zhuang))strSet = set (zhuang)# print(len(strSet), strSet)strDict = dict ()for word in strSet:    strDict[word] = zhuang.count (word)    # print(len(strDict), strDict)wcList = list (strDict.items ())# print(wcList)wcList.sort (key=lambda x: x[1], reverse=True)# print(wcList)for i in range (20):    print (wcList[i])

运行结果

 

 

转载于:https://www.cnblogs.com/fanfanfan/p/9712284.html

你可能感兴趣的文章
震撼可视化,讲述宇宙生命和宇宙垃圾
查看>>
如何在 Ubuntu16.04 中用 Apache 部署 Jenkins 自动化服务器
查看>>
《jQuery Cookbook中文版》——1.17 在不造成全局冲突的情况下使用$别名
查看>>
大数据常见术语表
查看>>
奥克斯天猫618首日破亿,有态度的国货空调说这是新常态
查看>>
《微软云计算Windows Azure开发与部署权威指南》——6.10 小结
查看>>
在UEFI模式下安装Ubuntu 14.04与Windows 8/8.1双启动
查看>>
《破茧成蝶——用户体验设计师的成长之路》—2.2 用户体验设计师的价值
查看>>
《CCNA学习指南:数据中心(640-911)》——2.4 小结
查看>>
《Android游戏开发详解》——第3章,第3.6节图形
查看>>
《Spring 5 官方文档》16.ORM和数据访问(三)
查看>>
格灵深瞳出手,灵异视频告破
查看>>
《OpenGL超级宝典(第5版)》——第1章,第1.4节3D编程的基本原则
查看>>
使用Observium来监控你的网络和服务器
查看>>
蚂蚁区块链团队资讯简报20170514
查看>>
阿里聚安全攻防挑战赛获奖名单公布
查看>>
当当网资深DBA:DB运维四大现代化的实现
查看>>
轻松搞定实时分析及监控大屏
查看>>
Spark应用(app jar)发布到Hadoop集群的过程
查看>>
OAuth 2.0 认证的原理与实践
查看>>