554544
#1 kkFile = open('kk.txt','r') kkTest = kkFile.read() kkFile.close() print(kkTest) #2 print(kkTest.replace(',',' ')) print(kkTest.replace("'",' ')) print(kkTest) #3 print(kkTest.split(' ')) kkList = kkTest.split(' ') #4 kkSet = set(kkList) print(kkSet) kkDict = {} for word in kkSet: kkDict[word] = kkList.count(word) print(kkDict) for d in kkDict: print(d,kkDict[d]) wordCountList = list(kkDict.items()) print(wordCountList) wordCountList.sort(key=lambda x:x[1],reverse=True print(wordCountList) for i in range(20): print(wordCountList[1])