綜合練習 詞頻統計

2022-06-04 04:36:10 字數 1037 閱讀 9503

song = '''

twinkle, twinkle, little star, how i wonder what you are. up above the world so high, like a diamond in the sky. twinkle, twinkle, little star, how i wonder what you are! when the blazing sun is gone, when he nothing shines upon, then you show your little light, twinkle, twinkle, all the night. twinkle, twinkle, little star, how i wonder what you are

'''#

分隔符全部替換為空格,大寫轉換為小寫,以空格劃分每個單詞

str1 = song.replace('

』','

').lower().split()

str2 =song.split()

#統計各單詞出現的次數

c ={}

for i in

str2:

count =str1.count(i)

c[i] =count

#去掉沒意義的單詞

word = '''

i you you're the a are in what how

'''str3 =word.split()

for i in

str3:

if i in

c.keys():

del(c[i])#排序

count = sorted(c.items(),key=lambda items: items[1], reverse=true)

#輸出詞頻最大10

綜合練習 詞頻統計

綜合練習 詞頻統計預處理 將所有,等分隔符全部替換為空格 將所有大寫轉換為小寫 生成單詞列表 生成詞頻統計 排序排除語法型詞彙,代詞 冠詞 連詞 輸出詞頻最大top20 將分析物件存為utf 8編碼的檔案,通過檔案讀取的方式獲得詞頻分析內容。從記事本長讀取檔案 f open news.txt r e...

綜合練習 詞頻統計

world f.read f.close xiaoqu depart for c in depart world world.replace c,wordlist world.lower split worddict wordset set wordlist xiaoqu for a in word...

綜合練習 詞頻統計

綜合練習 詞頻統計預處理 將所有,等分隔符全部替換為空格 將所有大寫轉換為小寫 生成單詞列表 生成詞頻統計 排序排除語法型詞彙,代詞 冠詞 連詞 輸出詞頻最大top20 將分析物件存為utf 8編碼的檔案,通過檔案讀取的方式獲得詞頻分析內容。f open news.txt r s f.read f....