Initial commit: Python learning project with examples and exercises

This commit is contained in:
2025-07-20 17:08:50 +08:00
commit bc7bb56271
111 changed files with 11535 additions and 0 deletions
@@ -0,0 +1,18 @@
#e10.3CalThreeKingdoms.py
from jieba import*
excludes = {} #{"将军","却说","丞相"}
txt = open("三国演义.txt", "r", encoding='utf_8').read()
words = lcut(txt) #jieba
counts = {}
for word in words:
if len(word) == 1: #排除单个字符的分词结果
continue
else:
counts[word] = counts.get(word,0) + 1
for word in excludes:
del(counts[word])
items = list(counts.items())
items.sort(key=lambda x:x[1], reverse=True)
for i in range(15):
word, count = items[i]
print ("{0:<10}{1:>5}".format(word, count))