#-*- 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. Android开源项目-Easypermissions

    Easypermissions简化了Android M的运行时权限的申请.结果处理.判断等步骤. 1 相关文档 官方文档: https://github.com/googlesamples/easyp ...

  2. 导入别人struts2项目可能要做的改变

    然后: 接着 再接着 最后

  3. FilterDispatcher处理流程

    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 前身是:org.apache.struts2.dispatc ...

  4. SEM

    SEM是Search Engine Marketing的缩写,中文意思是搜索引擎营销.SEM是一种新的网络营销形式.SEM所做的就是全面而有效的利用搜索引擎来进行网络营销和推广.SEM追求最高的性价比 ...

  5. Shell check IP

    #! /bin/bash checkip() {        if echo $1 |egrep -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3 ...

  6. linux中使用opdir_readdir读取目录中的信息

    #include <dirent.h>#include <stdio.h>#include <stdlib.h> int main(int argc, char * ...

  7. UVA - 11768 Lattice Point or Not (扩展欧几里得)

    求一条线段上有多少个整点. 是道扩欧基础题,列出两点式方程,然后分四种情况讨论即可.但细节处理较多很容易写挫(某zzWA了十几发才过掉的). 由于数据精度较小,浮点数比较没有用eps,直接==比较了. ...

  8. UVA - 11324 The Largest Clique (强连通缩点+dp)

    题目链接 题意:从有向图G中找到一个最大的点集,使得该点集中任意两个结点u,v满足u可达v或v可达u. 解法:先把同处于一个强连通分量中的结点合并(缩点),得到一张DAG图,在DAG上dp即可. 感觉 ...

  9. 欧拉函数 and 大数欧拉 (初步)

    前两天总结了素数筛法,其中就有Eular筛法.现在他又来了→→ φ(n),一般被称为欧拉函数.其定义为:小于n的正整数中与n互质的数的个数. 毕竟是伟大的数学家,所以以他名字命名的东西很多辣. 对于φ ...

  10. 1151 LCA in a Binary Tree(30 分)

    The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U ...