重複我有這樣一個代碼:計數單詞的列表中的PYTHON
s = "hello this is hello this is baby baby baby baby hello"
slist = s.split()
finallist = []
for word in slist:
if len(word) >= 4:
final = final + [word]
基本上這以上代碼,用於取列表,並僅把具有多於4個字符的單詞列表。
從這個列表中,我希望能夠統計同一單詞出現的次數並將其保存到新列表中。所以它會像[3,2,4] 3是你的時代,2是這個時代,4是嬰兒。
我建議這樣的:HTTP:// docs.python.org/2/library/collections.html#collections.Counter – squiguy 2013-03-06 03:13:27
看起來像作業。 – Demosthenex 2013-03-06 03:18:24
@squiguy謝謝你這是我正在尋找的文檔。 – 2013-03-07 04:24:37