求大佬解答pyhon中文词频统计

求大佬看一看

img

img

望采纳,可以参考下述代码过程:

# 导入必要的模块,如 `collections` 模块和 `jieba` 分词库:

import collections
import jieba

# 定义一个函数 `count_freq`,它接受一个文本字符串作为输入,并返回一个包含词频统计结果的字典:
def countfreq(text: str) -> dict:
    # 分词
    words = text.split("/")
    # 计数
    word_freq = collections.Counter(words)
    return word_freq

words_dict = countfreq('step1/words.txt')

if name == 'main':
  # 获取某个词词频
  word = input()
  count = word_dict.get(word, 0)
  print(count)