结果保存在result.txt文档内
# -*- coding: utf-8 -*- import jieba import sys from collections import Counter import jieba.analyse filename="招聘分析.txt" def fenci(filename) : f = open(filename,‘r+‘) file_list = f.read() f.close() seg_list = list(jieba.cut(file_list,cut_all=True)) tf={} for seg in seg_list : #print seg seg = ‘‘.join(seg.split()) if (seg != ‘‘ and seg != "\n" and seg != "\n\n") : if seg in tf : tf[seg] += 1 else : tf[seg] = 1 f = open("result.txt","w+") for item in tf: #print item f.write(item+" "+str(tf[item])+"\n") f.close() fenci(filename)
时间: 2024-10-07 08:41:23