1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python统计文本字符串里单词出现频率办法

python统计文本字符串里单词出现频率办法

时间:2024-08-11 13:37:38

相关推荐

python统计文本字符串里单词出现频率办法

后端开发|Python教程

python,统计,文本字符串,单词,频率

后端开发-Python教程

本文实例讲述了python统计文本字符串里单词出现频率的方法。分享给大家供大家参考。具体实现方法如下:

简单的个人视频网站源码,vscode下搭建c,ubuntu vlc下载,tomcat版本漏洞,sqlite 3导入数据库,如何用爬虫把字导入网页,php v6,镇江seo推广品牌公司,discuz x2.5 网站优化,手机网页模板 html5lzw

# word frequency in a text# tested with Python24 vegaseat 25aug# Chinese wisdom ...str1 = """Man who run in front of car, get tired.Man who run behind car, get exhausted."""print "Original string:"print str1print# create a list of words separated at whitespaceswordList1 = str1.split(None)# strip any punctuation marks and build modified word list# start with an empty listwordList2 = []for word1 in wordList1: # last character of each word lastchar = word1[-1:] # use a list of punctuation marks if lastchar in [",", ".", "!", "?", ";"]: word2 = word1.rstrip(lastchar) else: word2 = word1 # build a wordList of lower case modified words wordList2.append(word2.lower())print "Word list created from modified string:"print wordList2print# create a wordfrequency dictionary# start with an empty dictionaryfreqD2 = {}for word2 in wordList2: freqD2[word2] = freqD2.get(word2, 0) + 1# create a list of keys and sort the list# all words are lower case alreadykeyList = freqD2.keys()keyList.sort()print "Frequency of each word in the word list (sorted):"for key2 in keyList: print "%-10s %d" % (key2, freqD2[key2])

奇门遁甲软件源码,vscode边调试变插件,ubuntu 在线更新,tomcat修改启动参数,爬虫数据规则,php 二维数组下标,seo优化具体该怎么优化,免费企业网站模板html,登陆css模板lzw

vstart源码,vscode怎么运行html,ubuntu 视频,tomcat作用,for sqlite,好看的国外网页设计,织梦后台管理系统的数据怎么上传到数据库里面去,ftp服务器的ip地址查询,jquery zoom插件 下载,最流行前端框架,公众号爬虫,php管理系统,seo的网站,部署springboot项目,javascript 代码写在外部引用外部标签里面,ckplayer看电影网站,网页菜单显示英文,框架结构 模板,织梦后台管理界面模板,bootstrap产品展示页面,erp企业管理系统源码,批发网站程序lzw

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。