当前位置:   article > 正文

Python:词频统计(全)_python 总结文案字数出现的频次

python 总结文案字数出现的频次
# 中文
txt = input("请输入一段文本:")
d = {}
for i in txt:
    d[i] = d.get(i, 0) + 1  # 字典中的值
ls = list(d.items())
ls.sort(key=lambda x: x[1], reverse=True)  # 排序
for i in range(len(d)):
    word, count = ls[i]
    print("{:<10}{:<5}".format(word, count))

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

在这里插入图片描述

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

闽ICP备14008679号