sep=‘‘‘,.?!":‘‘‘ exclude={‘the‘,‘and‘,‘of‘,‘to‘} for c in sep: news=news.replace(c,‘ ‘) wordList=news.lower().split() wordDict={} wordSet=set(wordList)-exclude for w in wordSet: wordDict[w]=wordList.count(w) dictList=list(wordDict.items()) dictList.sort(key=lambda x:x[1],reverse=True) f=open(‘newscount.txt‘,‘a‘) for i in range(25): f.write(dictList[i][0]+‘ ‘+str(dictList[i][1])+‘\n‘) f.close()