统计英文歌词词频

s1='''Hold on to love 
that is what I do 
now that I've found you 
And from above  
everything's stinking they're not around you 
And in the night  
I could be helpless  
I could be lonely  
sleeping without you  
And in the day  
everything's complex  
There's nothing simple  
when I'm not around you  
But I miss you when you're gone  
that is what I do  
And it's going to carry on  
that is what I do  
Hold on to my hands 
I feel I'm sinking  
sinking without you  
And to my mind  
everything's stinking  
stinking without you '''
s1=s1.lower().replace("'s"," ").replace("i'm"," ").replace("and"," ").replace("to"," ").replace(" is"," ").replace("you"," ").replace("that"," ").replace(','," ").replace(" on"," ").replace("i "," ")
print(s1)
lyricsWordList=s1.split();
lyricsWordSet=set(lyricsWordList)
lyricsDict={}
for word in lyricsWordSet:
    lyricsDict[word]=lyricsWordList.count(word)
lyricsWordListSort=sorted(lyricsDict.items(),key=lambda d:d[1],reverse=True)
for i in range(10):
    if i>len(lyricsWordListSort):
        break
    print(lyricsWordListSort[i])

  

原文地址:https://www.cnblogs.com/zd983886992/p/8645553.html