标签:div .com items style lambda img ace bubuko set
qFile = open("q.txt",mode="r",encoding=‘utf-8‘) qText = qFile.read() qFile.close() print(qText) replaceList = [‘,‘,‘.‘,"‘",‘\n‘] for c in replaceList: qText = qText.replace(c,‘ ‘) print(qText) print(qText.split(‘ ‘)) qList = qText.split(‘ ‘) qSet = set(qList) print(qSet) qDict = {} for word in qSet: qDict[word] = qList.count(word) print(qDict) for d in qDict: print(d,qDict[d]) wordCountList = list(qDict.items()) print(wordCountList) wordCountList.sort(key=lambda x:x[1],reverse=True) print(wordCountList) for i in range(20): print(wordCountList) qCountFile = open(‘qCount.txt‘,mode=‘a‘,encoding=‘utf-8‘) for i in range(len(wordCountList)): qCountFile.write(str(wordCountList[i][1])+‘ ‘+wordCountList[i][0]+‘\n‘) qCountFile.close()
标签:div .com items style lambda img ace bubuko set
原文地址:https://www.cnblogs.com/whyyxxx/p/9206252.html