fo=open('test.txt','r') str=fo.read() fo.close() rap=''',?!''' exculde={'the','one','i','to','is','so','and','how','me'} for c in rap: str=str.replace(c," ") wordList=str.lower().split() wordDict={} wordSet=set(wordList) for c in wordList: wordDict[c]=wordList.count(c) for i in exculde: wordDict.pop(i) dictList = list(wordDict.items()) dictList.sort(key= lambda x:x[1],reverse=True) for i in range(10): print(dictList[i])