A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

单个字次数统计输出:

文字读取

>>> txt=open("C:\\WEXAM\\000000000000\\文本.txt","r").read()
1
标点符号识别

>>>for ch in ",。 ? : " :
        txt = txt.replace(ch,"")
1
2
读取并统计

>>>d = {}
>>> for ch in txt:
      d[ch]=d.get(ch,0)+1
>>> ls=list(d.items())
>>> ls.sort(key=lambda x:x[1],reverse=True)
>>> a,b=ls[0]
>>> print("{}:{}".format(a,b))
的:2557
1
2
3
4
5
6
7
8
输出词频统计top10

ls.sort(key=lambda x:x[1],reverse=True)
for i in range(10):
        print(str(ls)[2],end="")

       
的\"一我了是不有他
---------------------
【转载,仅作分享,侵删】
作者:那个年轻人
来源:CSDN
原文:https://blog.csdn.net/tandelin/article/details/88372927
版权声明:本文为博主原创文章,转载请附上博文链接!

1 个回复

倒序浏览
奈斯
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马