三國演義人物詞頻統計 2

2021-08-27 13:48:43 字數 713 閱讀 7948

對長度為1的單詞進行篩選

import jieba

path = 'c:\\users\\desktop\\三國演義.txt'

text = open(path,'r',encoding='utf-8').read()

#使用結巴的函式對文字進行分詞

words = jieba.lcut(text)

#定義字典型別去儲存文字和文字出現的次數

counts = {}

for word in words:

if len(word) == 1:

continue

else:

counts[word] = counts.get(word,0) + 1

items = list(counts.items())

#根據iems的第二個值進行從大到小的排序

items.sort(key = lambda x:x[1],reverse=true)

for i in range(10):

word,count = items[i]

#左對齊,佔位10位,填充字元為空格

三國演義人物詞頻統計 1

沒有把長度為1的單詞進行篩選 path c users desktop 三國演義.txt text open path,r encoding utf 8 read 使用結巴的函式對文字進行分詞 words jieba.lcut text 定義字典型別去儲存文字和文字出現的次數 counts for ...

python三國演義人物出場統計

開源 usr bin env python coding utf 8 e10.4calthreekingdoms.py import jieba excludes txt open threekingdom.txt rb read words jieba.lcut txt counts for wo...

《三國演義》簡介

三國演義 是我國最早的一部長篇 章回體歷史 描寫了 三國時期的歷史故事,集體表現了統治者之間政治和軍事鬥爭。該書最早的 版本是明 嘉靖元年刊印的 三國志通俗演義 分24卷,240則,每則乙個七言標題。此後新的刊本迭出,卷數 回目 引用詩詞等均有改動。清康熙時,毛綸 毛宗崗父子對 三國志演義 進行了修...