统计 THE TRAGEDY OF ROMEO AND JULIET (罗密欧与朱丽叶)英文小说中各单词出现的次数

mac2024-03-24  25

 作为python 练手的一个小例子

数据来源:

链接:https://pan.baidu.com/s/1u2c7O-617MboXSwBHnoOcA 提取码:vX47 

def words_static(file_path): words_static = dict() with open(file_path,"r") as file : for line in file: if line: words = line.split(" ") for word in words: words_static.setdefault(word,0) words_static[word] += 1 words_static_sorted = sorted(words_static.items(), key=lambda words_static:words_static[1],reverse = True) new_words_static_sorted = [] for i in words_static_sorted: new_words_static_sorted.append((i[1],i[0])) return new_words_static_sorted

 

 本例子来自于 浙江大学吴明辉教授在MOOC开设的 深度学习开发-Tensorflow 个人觉得讲解的非常好 刚兴趣的可以看一下 非常适合零基础的小白学习TensorFlow

最新回复(0)