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

 作为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

发布了42 篇原创文章 · 获赞 6 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/zkyxgs518/article/details/102833301