方法一:

 import operator
from nltk.corpus import stopwords
stop_words = stopwords.words('English')#目的是去除人称代词等,注意根据编译提示下载相应库 speech_text = '''
He is a good boy
She is a good girl
We are very nice
Hello boy hello boy
hello girl hello girl
hello dog
hello cat
hello pig
'''
speech = speech_text.lower().split()
dic = {}
for word in speech:
if word not in dic:
dic[word] = 1 #给词典赋值
else:
dic[word] = dic[word] + 1
swd = sorted(dic.items(), key = operator.itemgetter(1),reverse = True)
#stop_words
for k,v in swd:
if k not in stop_words:
print(k,v) print(swd)

方法二:

 import operator
from nltk.corpus import stopwords
stop_words = stopwords.words('English')#目的是去除人称代词等,注意根据编译提示下载相应库 speech_text = '''
He is a good boy
She is a good girl
We are very nice
Hello boy hello boy
hello girl hello girl
hello dog
hello cat
hello pig
'''
speech = speech_text.lower().split()
from collections import Counter
c = Counter(speech)
for sw in stop_words:
del c[sw]
print(c.most_common(10)) #打印前10项

python统计字词练习的更多相关文章

  1. python统计元素重复次数

    python统计元素重复次数 # !/usr/bin/python3.4 # -*- coding: utf-8 -*- from collections import Counter arr = [ ...

  2. 简易安装python统计包

    PythonCharm简易安装python统计包及 本文介绍使用pythonCharm IDE 来安装Python统计包或一些packages的简单过程,基本无任何技术难度,顺便提一提笔者在安装过程中 ...

  3. Python统计列表中的重复项出现的次数的方法

    本文实例展示了Python统计列表中的重复项出现的次数的方法,是一个很实用的功能,适合Python初学者学习借鉴.具体方法如下:对一个列表,比如[1,2,2,2,2,3,3,3,4,4,4,4],现在 ...

  4. Python统计日志中每个IP出现次数

    介绍了Python统计日志中每个IP出现次数的方法,实例分析了Python基于正则表达式解析日志文件的相关技巧,需要的朋友可以参考下 本脚本可用于多种日志类型 #-*- coding:utf-8 -* ...

  5. python 统计时间,写日志

    python 统计时间使用time模块,写日志使用logging模块,这两个都是标准模板. 测试socket使用socket模块 # 统计时间 ---------------------- impor ...

  6. python统计文本中每个单词出现的次数

    .python统计文本中每个单词出现的次数: #coding=utf-8 __author__ = 'zcg' import collections import os with open('abc. ...

  7. python统计文档中词频

    python统计文档中词频的小程序 python版本2.7 效果如下: 程序如下,测试文件与完整程序在我的github中 #统计空格数与单词数 本函数只返回了空格数 需要的可以自己返回多个值 def ...

  8. python统计字符串里每个字符的次数

    方法一: 推导式 dd="ewq4aewtaSDDSFDTFDSWQrtewtyufashas" print {i:dd.count(i) for i in dd} 方法二: co ...

  9. python 统计使用技巧

    python 统计使用技巧 # 1.不输入回车获取值 注:需要tty模块配合. fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) ...

随机推荐

  1. 深入剖析Kubernetes学习笔记:预习篇(01-04)

    01 初出茅庐 1.PaaS 项目被大家接纳的一个主要原因? 就是它提供了一种名叫"应用托管". 2.像 Cloud Foundry 这样的 PaaS 项目,最核心的组件是? 一套 ...

  2. Git 分支 (二)合并

    分支的新建与合并 让我们来看一个简单的分支新建与分支合并的例子,实际工作中你可能会用到类似的工作流. 你将经历如下步骤:1. 开发某个网站.2. 为实现某个新的需求,创建一个分支.3. 在这个分支上开 ...

  3. 语义化标签和jQuery选择器

    关于语义化标签 https://blog.csdn.net/nongweiyilady/article/details/53885433 更详细的语义化标签:https://www.cnblogs.c ...

  4. SpringBoot系列: Pebble模板引擎

    ===============================Java 模板引擎选择===============================SpringBoot Starter项目向导中可选的J ...

  5. yolo类检测算法解析——yolo v3

    每当听到有人问“如何入门计算机视觉”这个问题时,其实我内心是拒绝的,为什么呢?因为我们说的计算机视觉的发展史可谓很长了,它的分支很多,而且理论那是错综复杂交相辉映,就好像数学一样,如何学习数学?这问题 ...

  6. nnet3bin/nnet3-xvector-compute.cc

    将特征在xvector神经网络模型中前向传播,并写出输出向量.我们将说话人识别的特定神经网络结构的输出向量或embedding称之为"Xvector".该网络结构包括:帧级别的多个 ...

  7. Android屏幕旋转

    一个手机最基本的旋转方向有上面4种,而在Android开发中,涉及到屏幕旋转的地方很多,而且各个函数给出的角度值都不一样,比如 Activity的getRotate,Camera的setDisplay ...

  8. C# 在webapi项目中配置Swagger

    这篇文章已经过时了,新的主要配置一个就行了,请参照:http://www.cnblogs.com/alunchen/p/7397396.html Swagger是非常流行用于编辑api给前端同事用.或 ...

  9. Array数组小方法总结

    如果各位在阅读的时候,有任何问题,都可以留言: // push()方法会向数据末尾添加数据,并返回添加数据后的数组的长度var arr=[1,2,3]console.log(arr.push(4),a ...

  10. vue 3.0

    参照网址: https://blog.csdn.net/qq_36407748/article/details/80739787