python 统计西游记字数
import json fr = open("/home/xuefliang/PycharmProjects/Test/xyj.txt", "r") characters = [] stat = {} for line in fr: line = line.split() if len(line) == 0: continue # print type(line) temp = json.dumps(line, encoding="UTF-8", ensure_ascii=False) result = [t for t in temp][2:-2] for x in xrange(0, len(result)): if not result[x] in characters: characters.append(result[x]) if not stat.has_key(result[x]): stat[result[x]]=0 stat[result[x]]+=1fr.close()
评论
发表评论