綜合練習:詞頻統計
阿新 • • 發佈:2018-03-26
side st2 days pre forever oms rev item color
song = ‘‘‘ An empty street,An empty house,A hole inside my heart,I‘m all alone,The rooms are getting smaller,I wonder how,I wonder why,I wonder where they are,The days we had,The songs we sang together,Oh yeah,And oh my love,I‘m holding on forever,Reaching for a love that seems so far,So i say a little prayer,And hope my dreams will take me there,Where the skies are blue to see you once again, my love,Over seas and coast to coast,To find a place i love the most,Where the fields are green to see you once again, my love‘‘‘ wordlist1 = song.replace(‘’‘,‘ ‘).lower().split() wordlist2 = song.split() c = {} for i in wordlist2: count = wordlist1.count(i) c[i] = count word = ‘‘‘ i‘m you and the an a my i are ‘‘‘ wordlist3 = word.split() for i in wordlist3: if i in c.keys(): del (c[i]) count = sorted(c.items(),key=lambda items: items[1], reverse=True) for i in range(20): print(count[i])
綜合練習:詞頻統計