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]}"次')
2024-03-21 12:04:40
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]}"次')