大晋网,泾县房屋出租,大唐帝国游戏
GitHub地址: 【Give me a star , thanks.】
1 import string 2 from os import path 3 with open('瓦尔登湖(英文版).txt','rb') as text1: 4 words = [word.strip(string.punctuation).lower() for word in str(text1.read()).split()] 5 words_index = set(words) 6 count_dict = {index:words.count(index) for index in words_index} 7 with open(path.dirname(__file__) + '/file1.txt','a+') as text2: 8 text2.writelines('以下是词频统计的结果:' + '\n') 9 for word in sorted(count_dict,key=lambda x:count_dict[x],reverse=True): 10 text2.writelines('{}--{} times'.format(word,count_dict[word]) + '\n') 11 text1.close() 12 text2.close()
1 with open('瓦尔登湖(英文版).txt','rb') as text1:
GitHub地址: 【Give me a star , thanks.】
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
新手学习Python2和Python3中print不同的用法
Python基于os.environ从windows获取环境变量
网友评论