2012-04-05 38 views
-1

在Python 3.0.1中,我試圖使用collections模塊的Counter部分 無論我在文檔中看到什麼......都沒有說這個模塊的這部分不是在Python 3.0.1中可用。但...Python 3.0.1 collections.Counter

from collections import Counter 
from collections import counter 
from Collections import Counter 
from Collections import counter 

對我來說所有的產量錯誤......爲什麼這是???

回答

3

collections.Counter在版本3.1中添加。要麼升級到3.2,要麼自己實施該課程。有一個配方here.

+2

似乎配方是爲Python 2.x編寫的,如果您在Python 3.0中使用它,則需要將所有'iteritems'函數引用替換爲'items'。 – 2012-04-05 21:10:26

2

Counter類在3.0.1版本的python中不存在。它出現在3.1版本。

3

使用3.0 - 這是在抵達時基本死定了因爲它有嚴重的問題。獲得3.2,或者至少3.1。

相關問題