| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
- '''*************************************************************************
 
 -     @author:LaoGu
 
 -     @time: 2021/6/8
 
 -     @fuction:统计《三国演义-三英战吕布》中出场最多的前20位人物。
 
 - ****************************************************************************'''
 
 - import jieba
 
 - txt = open("三国演义-三英战吕布.txt","r").read()
 
 - words = jieba._lcut(txt)
 
 - counts = {}
 
 - for word in words:
 
 -     if len(word) == 1:
 
 -         continue
 
 -     else:
 
 -         counts[word] = counts.get(word,0) + 1
 
 - items = list(counts.items())
 
 - items.sort(key = lambda x : x[1],reverse = True)
 
 - print("《三国演义》中出场最多的前20位人物如下:")
 
 - for i in range(20):
 
 -     word,count = items[i]
 
 -     print("{0:>40}".format(word))
 
  复制代码 
 
结果如下: 
 
 |   
 
 
 
 |