思路:英文文章中的标点符号的处理,单词大小写的处理,再将单词通过字典的统计出现次数,最后用sorted()排序

#利用maketrans函数将标点符号映射为空格
table =str.maketrans(',.!"?:[]-',' ')
#打开需要统计的文件
f =open(r'C:\Users\CryptFiend\Downloads\python\1.txt')
file1 =f.read()
f.close()
#根据maketrans的映射将文章中的内容进行处理,映射中的标点符号替换为空格,并且全部小写
f1 =file1.translate(table).lower()
#将文章中的单词分隔开来,存在数组之中
wordlist =f1.split(None)
#创建一个字典,统计每个单词出现的次数
d1 ={}
forword inwordlist:
d1[word] =d1.get(word,0) +1
#通过sorted函数排序,打印出前三
itemli =sorted(d1.items(), key=lambdax:x[1],reverse=True)
print(itemli[0:3])

执行结果如下:
[('the', 23), ('to', 13), ('of', 11)]

#1.txt

Hillary Clinton's visit to India suffered another setback this week as the former secretary of state fractured her wrist after slipping in the bathtub at the five-star resort where she was staying, according to a report by DNA India.

The website reported that Clinton was taken to a hospital in the city of Jodphur at around 5 a.m. local time Wednesday. Clinton underwent an X-ray and a CT scan that confirmed a hairline fracture of her right wrist.

The Times of India reported that Clinton had been given a plaster bandage and advised to go for another checkup in three days. The injury does not impact Clinton's ability to travel.

The Times of India and DNA India both reported that Clinton had been treated for pain in her right hand since she arrived in Jodphur Tuesday afternoon. The pain forced her to cancel a planned visit to the 15th-century Mehrangarh Fort Tuesday evening.

Earlier in the week, video showed Clinton slipping on stairs twice as she visited the Jahaz Mahal in the ancient city of Mandu. Clinton appeared to use her right had to catch herself on the stairs, but it was not immediately clear whether this fall was the source of her injury.

At the time of her injury, Clinton was staying at the Umaid Bhawan Palace, which houses the onetime ruling family of Jodphur and also functions as a hotel -- offering rooms from $700 per night.

Clinton attracted controversy earlier in her visit to India. At a conference in Mumbai over the weekend, she again suggested that racism and misogyny were explanations for her loss in the 2016 presidential election.

"I won the places that represent two-thirds of America's gross domestic product," Clinton said. "So I won the places that are optimistic, diverse, dynamic, moving forward. And [President Trump's] whole campaign, 'Make America Great Again,' was looking backwards."

"You know, you didn't like black people getting rights, you don't like women, you know, getting jobs," she went on. "You don't want, you know, to see that Indian American succeeding more than you are."

Clinton also claimed that white women voted for Trump because they succumbed to "a sort of ongoing pressure to vote the way that your husband, your boss, your son, whoever, believes you should."

python3学习笔记之三——统计英文文章中出现次数最多的单词前三相关推荐

  1. java 单词出现次数_Java统计英文句子中出现次数最多的单词并计算出现次数的方法...

    搜索热词 本文实例讲述了Java统计英文句子中出现次数最多的单词并计算出现次数的方法.分享给大家供大家参考,具体如下: import java.util.*; /** * 统计出现次数最多的单词和它出 ...

  2. java统计每个单词单词出现的次数_Java统计英文句子中出现次数最多的单词并计算出现次数的方法...

    本文实例讲述了Java统计英文句子中出现次数最多的单词并计算出现次数的方法.分享给大家供大家参考,具体如下: import java.util.*; /** * 统计出现次数最多的单词和它出现的次数 ...

  3. 统计一篇英文文章中出现次数最多的10个单词

    https://blog.csdn.net/u010512607/article/details/40005641 思路: 1.读入文件,按行将文字拼接成字符串str 2.用正则过滤字符串中的标点,再 ...

  4. 统计英文字符串里重复次数最多的单词JAVA

    一次JAVA作业罢了 给定一段英文(看到内容感叹可怜的川宝倒了 我们想计算重复出现最多的单词,就会想要有两个信息 一是单词,二是单词出现的个数 HashMap提供的键值对存储方式可以很好地解决这个问题 ...

  5. Python每日一练(1):计算文件夹内各个文章中出现次数最多的单词

    #coding:utf-8 import os,repath = 'test' files = os.listdir(path)def count_word(words):dic = {}max = ...

  6. Java—统计一篇英文文章中出现的不重复单词的个数

    题目: 输入一篇英文文章,碰到"!!!"的时候停止,输出文章中出现的不重复单词的个数(注意:单词不区分大小写,如:The和the为一个单词) 输入格式: 一篇英文文章,以" ...

  7. python统计英文文章中单词出现的次数并排序_Python实现的统计文章单词次数功能示例...

    本文实例讲述了Python实现的统计文章单词次数功能.分享给大家供大家参考,具体如下: 题目是这样的:你有一个目录,放了你一个月的日记,都是 txt,为了避免分词的问题,假设内容都是英文,请统计出你认 ...

  8. C语言统计文章单词出现的次数,统计英文文章中单词出现频率

    /* 运行此程序之前要将写有单词的英文文章以.txt格式保存在d:\word.txt */ #include #include #include #include #include #include ...

  9. python统计英文文章中单词的个数无文件_求Python统计英文文件内单词个数的思路...

    感谢微博上@刘鑫-MarsLiu的TAG每天一个小程序. 你会如何实现上述题目的要求? #!/usr/bin/env python # -*- coding: utf-8 -*- "&quo ...

最新文章

  1. [php]如何做到高并发优化
  2. 2010.3.28 OA 项目组工作报告
  3. 贾君鹏你妈妈喊你回家吃饭
  4. excel数据命令导入mysql_如何将EXCEL数据导入MYSQL
  5. LeetCode--34.在排序数组中查找元素第一个和最后一个位置(二分法)
  6. PyTorch 1.0 中文文档:多进程最佳实践
  7. 一篇文章告诉你[C++]数组初始化
  8. 周界防护在安防行业重要性与日俱增
  9. keil如何下载STM32芯片F1/F4固件库
  10. X509TrustManager信任SSL证书
  11. 双硬盘安装win7和Ubuntu双系统,解决系统启动引导问题
  12. 本科计算机考研考英语,2016考研必需知道的10件事
  13. cad菜单栏快捷键_天正建筑菜单栏不见了怎么调出来
  14. 智能合约节省GAS的小技巧:避免使用>=和<=
  15. HDU 5441并查集 by cyl
  16. 时钟树综合CTS技术经验分享(高薪必备)
  17. 【组合数学】组合恒等式 ( 组合恒等式 积之和 1 | 积之和 1 证明 | 组合恒等式 积之和 2 | 积之和 2 证明 )
  18. python爬取高匿代理IP(再也不用担心会进小黑屋了)
  19. 华为机试:火星符号运算
  20. 鼠标移动到图片上实现图片的放大缩小

热门文章

  1. 我的体会:十年编程无师自通
  2. 《黑神话:悟空》将登陆哪些平台 登陆平台介绍
  3. 磁盘符上有个锁的标志,bitlocker恢复密钥 解决办法
  4. 比心聊天室的架构演进
  5. android娃娃机源码,微信夹娃娃游戏娃娃机完整开源版源码(安装教程+三方支付)...
  6. 首个开源 Linux 系统登陆火星,一同登录还有一款安卓手机芯片
  7. maven testNG打成jar包运行报错repackage failed: Unable to find main class
  8. 【蓝桥杯】 C++ 成绩统计
  9. 基于MATLAB课堂考勤(GUI)
  10. PROFIBUS Tester 5(BC-700-PB)