资源简介
file=open("考研英语真题.txt",'r',encoding='UTF-8')
只要把文件放在同一目录下,在上面这一行中改一下文件名就行。
考研时候感觉辅导书上的高频词汇有点问题,就写了这么个程序^_^

代码片段和文件信息
import re
#coding=utf-8
file=open(“考研英语真题.txt“‘r‘encoding=‘UTF-8‘)
file_context=file.read()
#print (file_context)
file.close()
print (‘file read over and colsed‘)
print (‘##‘*40)
word_dric={}
all_words_list=[]
all_words_list =re.findall (r‘.+?\b‘file_context) #find all the words
#print (all_words_list)
print (‘find all the words‘)
print (‘##‘*40)
for word in all_words_list:
if word in word_dric:
word_dric[word]=word_dric[word]+1
else:
word_dric[word]=1
print (‘words occurrences count over‘)
print (‘##‘*40)
sortedlist =sorted(word_dric.items()key = lambda x:x[1]reverse = True)
#print (sortedlist)
print(‘sorted over‘)
print (‘##‘*40)
file=open(“process_result.txt“‘w‘encoding=‘UTF-8‘)
for item in sortedlist:
file.write(str(item))
file.write(‘\n‘)
file.close()
print (‘result write into txt over‘)
‘‘‘
file=open(“process_result.txt“‘w‘encoding=‘UTF-8‘)
for word in word_dric:
file.write(word)
file.write(‘ :‘)
file.write( str(word_dric[word]) )
file.write(‘\n‘)
file.close()
print (‘result write over‘)
‘‘‘
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1159 2019-01-21 12:43 count_words_occurrences.py
文件 1083609 2019-01-21 03:34 考研英语真题.txt
- 上一篇:高效算法128例配套代码
- 下一篇:Arcpy实现dem河网提取
相关资源
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
- python 名字用字排行
评论
共有 条评论