https://blog.csdn.net/qq_45726327/article/details/115042863
s = input("请输入一个字符串:") print("{:*^30}".format(s))
https://blog.csdn.net/qq_52351158/article/details/122209848
import jieba txt = input("请输入一段中文文本:") ls = jieba.lcut(txt) for i in ls[::-1]: print(i,end = "")
*****
fo = open("PY202.txt","w") txt = input("请输入类型序列: ") fruits = txt.split(" ") d = {} for i in fruits: d[i] = d.get(i,0)+1 ls = list(d.items()) ls.sort(key=lambda x:x[1], reverse=True) # 按照数量排序 for k in ls: fo.write("{}:{}\n".format(k[0], k[1])) fo.close()
=================================================================================================================================================
--------------------------大题001----------------------------------
#请在.....处填写多行表达式或语句 #可以修改其他代码 f = open("八十天环游地球.txt") fo = open("八十天环游地区的章节.txt",'w') for i in f: line = i.strip().split() if line[0][0]=='第' and '章' in line[0]: fo.write(i) fo.close() f.close()
复习:
import jieba f = open("八十天环游地球.txt") datas = f.readlines() l = [] for i in range(len(datas)): #遍历每一行,用l数组存储每一个行的行数。 line = datas[i].split('') if datas[i][0]=='第' and '章' in line[0]: l.append(i) for i in range(len(l)): if i != len(l)-1: data = "".join(datas[l[i]:l[i+1]]) #所有章节的行数拼接 else: data = "".join(datas[l[i]:]) #最后一章的处理 s = data.split()[0] #章节名提取 words = jieba.lcut(data) #jieba分词 d ={} for y in words: if(len(y)<2): #词语长度不小于2的要求 continue d[y]=d.get(y,0)+1 #统计词语的次数 lis = list(d.item()) #将字典变成列表方便排序 lis.sort(key = lambda x:x[1],reverse = True)#排序 print(s,lis[0][0],lis[0][1])
标签:二级,jieba,计算机,操作题,ls,line,txt,datas,fo From: https://www.cnblogs.com/MrMKG/p/16563400.html