WordsCount(词频统计)-Python语言编写!

词频统计代码,python语言!可将结果输出到文件!


dic={}

for i in open('D:\object_bj.txt'):
        array=[]
        i=i.strip()
        array=i.split()
        for j in array:
                if not dic.has_key(j):
                        dic[j]=0
                dic[j]+=1
f=open('D:\object_bj_out.txt','w')
for i in dic.keys():
    f.write (i+'\t'+str(dic[i])+'\n')
f.close()


你可能感兴趣的:(python,词频统计,WordsCount)