1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python统计出现次数最多的一个词语_python取一个字符串中最多出现次数的词

python统计出现次数最多的一个词语_python取一个字符串中最多出现次数的词

时间:2020-09-26 10:37:30

相关推荐

python统计出现次数最多的一个词语_python取一个字符串中最多出现次数的词

#-*- coding:utf-8 -*-

#取一个字符串中最多出现次数的词

import re

from collections import Counter

my_str = """

Simple is better than complex.

Complex is better than complicated.

Flat is better than nested.

Sparse is better than dense.

Readability counts.

Special cases aren't special enough to break the rules.

Although practicality beats purity.

Errors should never pass silently.

Unless explicitly silenced.

In the face of ambiguity, refuse the temptation to guess.

There should be one-- and preferably only one --obvious way to do it.

Although that way may not be obvious at first unless you're Dutch.

Now is better than never.

Although never is often better than *right* now.

If the implementation is hard to explain, it's a bad idea.

If the implementation is easy to explain, it may be a good idea.

Namespaces are one honking great idea -- let's do more of those!

"""

word_count = Counter(re.split('[ .,;~!-<>/|@#$%^&*?\n\t]', my_str))

#取非空的前八个最多单词

most_11 = [x for x in word_count.most_common(8) if x[0] != ""]

#直接取前八个最多单词

print word_count.most_common(8)

print(most_11)

for i in most_11:

print i[0]

Java实现统计某字符串在另一个字符串中出现的次数

面试时会经常考这样的题目,估计也不让使用正则表达式.还好这个算法还算简单,不过在草稿纸上写难免会出现运行异常,好吧,面试官赢了,乃们屌丝就实实在在的把代码码出来吧. 谢谢“心扉”对我代码bug的纠正, ...

C语言:利用指针解决:统计一个长度为2的字符串在另外一个字符串中出现的次数。

//统计一个长度为2的字符串在另外一个字符串中出现的次数. #include #include #include

Python判断一个字符串中是否存在多个子串中的一个

在使用python的开发过程中,常常需要判断,字符串中是否存在子串的问题, 但判断一个字符串中是否存在多个字串中的一个时,如if (a or b) in c或者if x contains a|b|c| ...

MSSQL sqlserver 统计&quot&semi;一个字符串&quot&semi;在&quot&semi;另一个字符串&quot&semi;中出现的次数的方法

转自/?p=9858 摘要: 下文讲述sqlserver中最快获取一个字符串在另一个字符串中出现个数的方法分享 实验环境:sql server 20 ...

python之统计字符串中字母出现次数

dic=dict() d={} s=set() s='helloworld' (1)d=dict() for x in s: if x not in d.keys(): d[x]=1 else: d[ ...

php 计算一个字符串在另一个字符串中出现的次数

SQL语句 查询同一个字符在某一个字符串中出现的次数

select len(replace(字段名A,';','--'))-len(字段名A) from table表名

javascript 写一段代码,判断一个字符串中出现次数最多的字符串,并统计出现的次数

javascript 写一段代码,判断一个字符串中出现次数最多的字符串,并统计出现的次数 function test(){ var bt = document.getElementById(&quot ...

随机推荐

remove mysql

apt-get --purge remove mysql-server mysql-client mysql-common apt-get autoremove rm -rf /etc/mysql r ...

11月9日 星期三 --出埃及记 Exodus 19&colon;25

11月9日 星期三 --出埃及记 Exodus 19:25 So Moses went down to the people and told them.于是摩西下到百姓那里告诉他们.

&dollar;&period;extend abc

console.log(jQuery.extend(this,{'a':'b'},{'c':'d'}));console.log(this.a)var tt = jQuery.extend({},{' ...

Elasticsearch从0&period;90到1&period;2的不兼容变化-系统和设置

本文为官方文档的翻译加个人理解.作者翻译时,elasticsearch(下面简称es)的版本为1.2.1. 1.系统级别及设置方面 1.1 es启动时,默认是作为一个前台程序启动.如果你想让e ...

angular调用WCF服务,读取文件夹下图片显示列表,下载另存为图片

读取文件夹下的文件 public string ReadImagesPaths() { string result = string.Empty; try { string path = System ...

PostScript学习:另一种缩写为PS的技术

1.前言 PostScript是一种编程语言,直译为"后处理脚本"[相对印刷过程而言],学名为页面描述语言.更为详细的解释见维基百科,以及其翻译版百度百科. 值得一提的是,Post ...

Ext&period;Msg&period;alert添加确定按钮

Ext.Msg.alert('成功','成功!!', function(btn){ if(btn!=null{//btn=='ok'||btn=='cancel' ... } });

WordPress非插件实现评论回复邮件提醒通知

要想在第一时间知道有人在自己博客留言,然后在第一时间回复留言再第一时间通知邮件者,这就需要WordPress博客拥有邮件通知功能. 先看效果: 评论邮件通知的方法: 1.所有回复都发送邮件通知 登陆博 ...

java class反编译工具----JD-GUI

下载地址 http://jd.benow.ca/

Linux 下 mysql的基本配置

Linux 下 mysql的基本配置 02月27日 ⁄ MySQL ⁄ 共 3000字 ⁄ 暂无评论 ⁄ 被围观 2,483 views+ 1. Linux mysql安装: $ yu ...

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