1.读入待分析的字符串

 1 fo=open('test.txt','w')
 2 fo.write('''You gotta go and get angry at all of my honesty
 3 You know I try but I don’t do too well with apologies
 4 I hope I don’t run out of time, could someone call a referee?
 5 Cause I just need one more shot at forgiveness
 6 I know you know that I made those mistakes maybe once or twice
 7 By once or twice I mean maybe a couple a hundred times
 8 So let me, oh let me redeem, oh redeem, oh myself tonight
 9 Cause I just need one more shot at second chances
10 Yeah, is it too late now to say sorry?
11 Cause I’m missing more than just your body
12 Is it too late now to say sorry?
13 Yeah I know that I let you down
14 Is it too late to say I’m sorry now?
15 I’m sorry, yeah
16 Sorry, yeah
17 Sorry
18 Yeah I know that I let you down
19 Is it too late to say sorry now?
20 I’ll take every single piece of the blame if you want me to
21 But you know that there is no innocent one in this game for two
22 I’ll go, I’ll go and then you go, you go out and spill the truth
23 Can we both say the words and forget this?
24 Is it too late now to say sorry?
25 Cause I’m missing more than just your body
26 Is it too late now to say sorry?
27 Yeah I know that I let you down
28 Is it too late to say I’m sorry now?
29 I’m not just trying to get you back on me
30 Cause I’m missing more than just your body
31 Is it too late now to say sorry?
32 Yeah I know that I let you down
33 Is it too late to say sorry now?
34 I’m sorry, yeah
35 Sorry, oh
36 Sorry
37 Yeah I know that I let you down
38 Is it too late to say sorry now?
39 I’m sorry, yeah
40 Sorry, oh
41 Sorry
42 Yeah I know that I let you down
43 Is it too late to say sorry now?''')
44 fo.close()

fo=open('test.txt','r')
   sorry=fo.read()

2.分解提取单词

sorry=sorry.lower()
for i in '?,':sorry=sorry.replace(i,' ')
words=sorry.split(' ')#以空格分隔
print(words)

3.计数字典

4.排除语法型词汇

dic={}#定义一个空字典
words.sort()#排列切片好的单词
d=set(words)#集合d的元素就是切片好的单词
for i in d:dic[i]=words.count(i)#循环插入值为空的主键i

5.排序

wc=list(dic.items())wc.sort(key=lambda x:x[1],reverse=True)#排序

6.输出TOP(20)

for i in range(20):print(wc[i])

运行结果:

转载于:https://www.cnblogs.com/zhuyinyinyin/p/7595206.html

1.读入待分析的字符串 2.分解提取单词 3.计数字典 4.排除语法型词汇 5.排序 6.输出TOP(20)...相关推荐

  1. 小娴的男友小旭不幸患了一种怪病,这种怪病吞噬了他的大部分记忆,同时让他突然间不会书写符合正确语序的英文。神奇的是,虽然他写出的句子看上去杂乱无章,不过经过仔细分析可以发现,如果把单词的顺序倒过来,语法

    题目描述 小娴的男友小旭不幸患了一种怪病,这种怪病吞噬了他的大部分记忆,同时让他突然间不会书写符合正确语序的英文.神奇的是,虽然他写出的句子看上去杂乱无章,不过经过仔细分析可以发现,如果把单词的顺序倒 ...

  2. 作业9-文件方式实现完整的英文词频统计实例

    1.读入待分析的字符串 2.分解提取单词 3.计数字典 4.排除语法型词汇 5.排序 6.输出TOP(20) ============================ 运行结果为: 转载于:https ...

  3. 文件方式实现完整的英文词频统计实例(9.27)

    1.读入待分析的字符串 2.分解提取单词 3.计数字典 4.排除语法型词汇 5.排序 6.输出TOP(20) 文本代码如下: girl='''Remembering me, Discover and ...

  4. 文件方式实现完整的英文词频统计实例

    可以下载一长篇的英文小说,进行词频的分析. 1.读入待分析的字符串 2.分解提取单词 3.计数字典 4.排除语法型词汇 5.排序 6.输出TOP(20) 7.对输出结果的简要说明. fo=open(' ...

  5. 在单缓冲区和双缓冲区结构下,读入并分析完该文件的时间分别是

    链接:https://www.nowcoder.com/questionTerminal/5a9eff01452240a7a97495cef08ad3f6?toCommentId=398027 来源: ...

  6. 关于读入带空格的字符串与输入输出重定向

    一.读入带空格的字符串 由于NOIP官方开始使用C++14编译器,C语言中用于读取带空格字符串的gets()函数已经不可以再用了.作为替代,有以下方法. cin.getline()函数. 函数格式: ...

  7. 使用C语言分析分析英文字符串中的单词

    @[TOC] 使用C语言分析分析英文字符串中的单词 分析英文字符串时会产生的问题 比如一句英文: we eat dinner at four o'clock,noodles is delicious. ...

  8. 深信服:输入一个字符串,帮忙统计字符串里面的每个单词出现的次数,以及非法单词的次数。非法单词的定义为:包含数字(0-9)的单词

    深信服2018秋招笔试题: 输入一个字符串,帮忙统计字符串里面的每个单词出现的次数,以及非法单词的次数.非法单词的定义为:包含数字(0-9)的单词 输入一个字符串,长度小于1000,输入的字符仅包含( ...

  9. c语言单词的一个字母变换,c语言:输入一行英文字符串,把每个单词第一个字母变为大写,输出修改后的字符串知道...

    #include #include #include int main(int argc,char*argv[]) { char str[100+1]; int isfirst=1; char ch; ...

最新文章

  1. 【微信小程序之画布】一:canvas组件
  2. Spring Boot + Mybatis 多模块(module)项目的完整搭建教程
  3. 14 图的基础知识-几种常用的存储结构
  4. 打包成单独的HTML文件,【WEBPACK】分离css单独打包
  5. Linux Kernel中的系统调用分析
  6. android+java.lang.VerifyError
  7. 新版CSDN中如何快速转载别人的CSDN博客,详细方法与步骤!!!
  8. LinQ To Object 基本用法
  9. SQLCLR(一)入门
  10. windows+cygwin+ns2的安装过程及相关问题
  11. 作为一个技术人,我究竟要什么?
  12. 用C#,SQL Server编写的音乐播放软件
  13. 中国科学院微电子学院计算机,周云燕 - 中国科学院大学 - 微电子学院
  14. 在PC上使用苹果蓝牙无线键盘
  15. I2C 总线协议初探 - STM32 I2C 接口外设学习笔记
  16. MTK手机充电原理分析及问题总结
  17. 版本号后面有SNAPSHOT是什么意思
  18. Unity HDRP室外场景打光流程分享(上篇)-UE4场景转Unity HDRP
  19. 数据结构荣誉课-第一次实验-解题报告
  20. nginx的全局配置和HTTP相关配置

热门文章

  1. 资料下载:敏捷个人的成长思考.pptx(第1次线下活动2011.04)
  2. [Springboot]SpringCache + Redis实现数据缓存
  3. 教你如何监控 Apache?
  4. Loadrunner报错“Too many local variablesAction.c”解决方法
  5. linux 模拟延时和丢包
  6. 飞翔的圆(Flappy Bird)游戏源码完整版
  7. as与asp.net通信
  8. 请列举中图片内存处理的六种方法,并简单介绍
  9. PL/SQL Developer 更改字体
  10. php 截取www后面的目录,php-如何从字符串路径中获取最后一个目录