#-*- 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]

python取一个字符串中最多出现次数的词的更多相关文章

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

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

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

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

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

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

  4. MSSQL sqlserver 统计"一个字符串"在"另一个字符串"中出现的次数的方法

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

  5. 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[ ...

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

    <?php $text = 'This is a test'; echo strlen($text); // 14 echo substr_count($text, 'is'); // 2 // ...

  7. JS求一个字符串在另一个字符串中出现的次数

    参数说明: subString子字符串 originString母字符串 isIgnoreCap是否忽略大小写,默认忽略 function stringFre(subString, originStr ...

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

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

  9. 一个字符串中可能包含a~z中的多个字符,如有重复,如String data="aavzcadfdsfsdhshgWasdfasdf",求出现次数最多的那个字母及次数,如有多个重复的则都求出。

    主要掌握String中的方法 char[] toCharArray()           将此字符串转换为一个新的字符数组. int indexOf(String str)           返回 ...

随机推荐

  1. unity脚本生命流程

    渲染 OnPreCull: 在相机剔除场景之前调用此函数.相机可见的对象取决于剔除.OnPreCull 函数调用发生在剔除之前. OnBecameVisible/OnBecameInvisible:  ...

  2. TemplatedParent 与 TemplateBinding

    http://blog.csdn.net/idebian/article/details/8761388

  3. javascript给输入框赋值的一个误区

    一. 错误的示范 如下代码所示,如果需要用javascript获取id为username1, password1的输入框的值,将其写入id为username2, password2的输入框,那么红线区 ...

  4. VSCode设置中文语言显示

    Vscode是一款开源的跨平台编辑器.默认情况下,vscode使用的语言为英文(us),如何将其显示语言修改成中文了? 1)打开vscode工具: 2)使用快捷键组合[Ctrl+Shift+p],在搜 ...

  5. hdoj-1106-排序(stringstream)

    题目链接 /* Name: Copyright: Author: Date: 2018/5/2 20:56:53 Description: */ #include <iostream> # ...

  6. InnoDB参数详解

    1.查询5.5版本的InnoDB参数并注释:[root@localhost etc]# grep -i innodb my.cnf; t_innodb; otherwise, slaves may d ...

  7. java web工程启动socket服务

    1.新建web工程 2.自定义类 实现ServletContextListener 接口 在contextInitialized方法中启动socket服务的线程 在contextDestroyed方法 ...

  8. mysql 权限的相应修改

    mysql 权限的相应修改 UPDATE user SET Password = PASSWORD('bbbb') WHERE user = 'root';flush privileges; upda ...

  9. BZOJ4355: Play with sequence

    BZOJ4355: Play with sequence https://lydsy.com/JudgeOnline/problem.php?id=4355 分析: 模板题. 把\(2\)操作看成先区 ...

  10. TP上传图片

    //更新 更新中的话,一定要写那一个if判断 public function update(){ $model = M('link'); $upload = new \Think\Upload();/ ...