#字频统计
# -*- coding: utf-8 -*-
# coding=utf-8
import collections
# 读取文本文件,把所有的汉字拆成一个list
f = open("D:\python\pra\推荐系统1-500.txt", 'r', encoding='utf-8') # 打开文件,并读取要处理的大段文字
txt1 = f.read()
txt1 = txt1.replace('\n', '') # 删掉换行符
txt1 = txt1.replace(',', '') # 删掉逗号
txt1 = txt1.replace('。', '') # 删掉句号
mylist = list(txt1)
mycount = collections.Counter(mylist)
for key, val in mycount.most_common(50): # 有序(返回前10个)
print(key, val)

#词频统计
# -*- coding: utf-8 -*-
# coding=utf-8
import jieba
import jieba.analyse
# text = "故宫的著名景点包括乾清宫、太和殿和午门等。其中乾清宫非常精美,午门是紫禁城的正门,午门居中向阳。"
text = ''
#jieba.load_userdict("jieba_dict.txt") # 用户自定义词典 (用