首页 > 其他 > 详细

6.20

时间:2018-06-20 22:16:21      阅读:192      评论:0      收藏:0      [点我收藏+]
技术分享图片
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()

 


技术分享图片技术分享图片

6.20

原文:https://www.cnblogs.com/whyyxxx/p/9206252.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!