从文件中统计中文词语出现的频次

 1 import jieba
 2 
 3 with open('红楼梦.txt', 'r', encoding='utf-8') as f:
 4     txt = f.read()
 5 
 6 ls = jieba.lcut(txt)
 7 d = {}
 8 for w in ls:
 9     d[w] = d.get(w, 0) + 1
10 
11 for k in d:
12     if d[k] >= 200 and len(k) >= 2:
13         print(f'"{k}"出现了"{d[k]}"次')
原文地址:https://www.cnblogs.com/waterr/p/14801163.html