Python计算机二级,请教一下

问题:(主要是第七个空真的不会)
汉语中结构助词主要表示附加成分和中心语之间的结构关系,在书面语里结构助词习惯写成三个字:“的”、“地”、“得”。这样可以使书面语里的结构关系更清楚。请统计 sefile104.txt
文件中的结构助词的种类,并把每种结构助词按个数从少到多排列,然后把个数输出到屏幕,格式要求:宽度为 5 个字符,减号字符-填充,右对齐。注意 sefile104.txt 文件的编码为 UTF-8(UTF-8 使用大写),程序中的字符串全部使用双引号
""表示。
请把编号(1)~(10)和对应下划线删除,填空完成程序中的语句,不能修改已有的代码。
import jieba
list_names=["的","地","得"]
list1=[]
count={} #用来计数
with open("sefile104.txt","r",(1)) as f: #1
txt=f.
(2) #2
words=
(3)(txt) #3 使用精确模式进行分词
for word in words:
if word (4) list_names: #4 如果单词不是结构助词,那就不记录这个分词了
(5) #5
list1.append(word)
count[word]= (6)+1 #6
kind=
(7)_(list1)) #7 统计文件中结构助词出现的种类
print("sefile104.txt 文件中结构助词的种类有:%d"%kind)
items=
(8)
_
(count.items()) #8 将其返回为列表类型
items.sort(key=lambda x:x[1],
(9)__) #9 按个数升序排序
for i in range(kind):
var,number=items[i]
print('文件中"{0}"字出现次数为{ (10)
}'.format(var,number)) #10

img

7空要填的是 len(set(, 列表转集合用set()去重,然后用len()得到种类数kind

import jieba
list_names=["的","地","得"]
list1=[]
count={} #用来计数
with open("test.txt","r",encoding='UTF-8') as f: #1
    txt = f.read() #2
    words=jieba.cut(txt) #3 使用精确模式进行分词
for word in words:
    if word not in list_names: #4 如果单词不是结构助词,那就不记录这个分词了
        continue #5
    list1.append(word)
    count[word]= count.get(word,0)+1 #6
    kind = len(set(list1)) #7 统计文件中结构助词出现的种类
        
print("sefile104.txt 文件中结构助词的种类有:%d"%kind)

items=list(count.items()) #8 将其返回为列表类型
items.sort(key=lambda x:x[1],reverse=True) #9 按个数升序排序
for i in range(kind):
    var,number=items[i]
    print('文件中"{0}"字出现次数为{1:->5}'.format(var,number)) #10

是不是准备广东的python二级