asdasf

bigFile = open('big.txt',mode='r',encoding='utf-8')
bigText = bigFile.read()
bigFile.close()
print(bigText)


replaceList=[',','.',"'",'\n']
for c in replaceList:
    bigText = bigText.replace(c,'')
print(bigText)



print(bigText.split(' '))
bigList=bigText.split(' ')
print(bigList.count('big'))

bigSet = set(bigList)
print(bigSet)

bigDict ={ }
for word in bigSet:
    bigDict[word] = bigList.count(word)

    print(bigDict)
    for d in bigDict:
     print(d,bigDict[d])


wordCountList = list(bigDict.items())
print(wordCountList)
wordCountList.sort(key=lambda x:x[1],reverse=True)
print(wordCountList)

for i in range(20):
    print(wordCountList[i])

bigCountFile = open('bigCount.txt', mode='a',encoding='utf-8')
for i in range(len(wordCountList)):
    bigCountFile.write(str(wordCountList[i][1])+' '+wordCountList[i][0]+'\n')
bigCountFile.close()

  asdasf_第1张图片

你可能感兴趣的:(asdasf)