当前位置:   article > 正文

用Python实现词频统计_词频统计实验python

词频统计实验python
  1. #词频统计
  2. a = "And how will this be accomplished? For I have neither the knowledge nor the experience to achieve the greatness and already I have stumbled in ignorance and fallen into pools of self-pity. The answer is simple. I will commence my journey unencumbered with either the weight of unnecessary knowledge or the handicap of meaningless experience. Nature already has supplied me with knowledge and instinct far greater than any beast in the forest and the value of experience is overrated, usually by old men who nod wisely and speak stupidly."
  3. #(1)大小写同一
  4. a = a.lower()
  5. print(a)
  6. #转化为小写
  7. #(2)切分
  8. result = a.split()
  9. print(result)
  10. #(3)遍历
  11. #定义储存字典
  12. re = {}
  13. for word in result:
  14. l = word.strip()#去除两边空格
  15. re[l] = re.get(l,0)+1
  16. print(re)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/384139
推荐阅读
相关标签
  

闽ICP备14008679号