如何使用FreqDist中的fd.items()來總結詞頻數量?使用FreqDist總結詞頻數量,python
>>> fd = FreqDist(text)
>>> most_freq_w = fd.keys()[:10] #gives me the most 10 frequent words in the text
>>> #here I should sum up numbers of each of these 10 freq words appear in the text
例如,如果most_freq_w
中的每個單詞出現10次,結果應該是100
!!!我不需要這個數字的所有詞語的文字,只是最常見的10
認爲(這幾乎是侮辱性的簡單)。或者至少向我們展示你的嘗試。 – delnan 2010-11-17 17:05:06
我試過的是將'fd.items'從'most_freq_w'中取出 - 但這是絕對錯誤的,因爲結果爲'0' – Gusto 2010-11-17 17:27:14