# -*- coding: UTF-8 -*-str = '''Gotta Have You (The Weepies)Gray, quiet and tired and meanPicking at a worried seamI try to make you mad at me over the phoneRed eyes and fire and signsI'm taken by a nursery rhymeI want to make a ray of sunshine and never leave homeNo amount of coffeeNo amount of cryingNo amount of whiskeyNo amount of wineNo, nothing else will doI've gotta have youI've gotta have youThe road gets coldThere's no spring in the middle this yearI'm the new chicken clucking open hearts and earsOh, such a prima DonnaSorry for myselfBut green, it is also summerAnd I won't be warm till I'm lying in your armsNo amount of coffeeNo amount of cryingNo amount of whiskeyNo amount of wineNo, nothing else will doI've gotta have youI've gotta have youI see it all through a telescope:Guitar, suitcase, and a warm coatLying in the back of the blue boatHumming a tune...No amount of coffeeNo amount of cryingNo amount of whiskeyNo wineNo, nothing else will doI've gotta have youI've gotta have youNo amount of coffeeNo amount of cryingNo amount of whiskeyNo amount of wineNo, nothing else will doI've gotta have you ~~gotta have youI've gotta have you'''n='''~,.'"?!;)('''exclude = { 'the','a','of','to','for','in','and','no','i','you','ve','have'}for t in n: str = str.replace(t,' ')wordList = str.lower().split()wordDict = {}wordSet = set(wordList)for w in wordSet: wordDict[w] = wordList.count(w)for w in wordList: wordDict[w] = wordDict.get(w,0)+1for w in exclude: wordDict.pop(w)dictList = list(wordDict.items())dictList.sort(key=lambda x: x[1], reverse=True)for w in dictList: print(w)
f = open('C:\Users\Administrator\PycharmProjects\bd\so.txt','r')text = f.read()f.close()print(text)