我当前使用的是python版本3.7,每次尝试从collections模块导入counter时,都会出现错误。
from collections import counter
ImportError Traceback (most recent call
last)
<ipython-input-34-8cabd9ed4f3e> in <module>
----> 1 from collections import counter
ImportError: cannot import name 'counter' from 'collections'
(D:\python\lib\collections\__init__.py)
并且当我尝试通过使用collections.counter()手动进行操作时,它会告诉我“模块'collections'没有属性'counter'。我知道counter仅在2.7之后实现,但目前在3.7(如果我没记错的话,根据我的jupyter笔记本,我的python肯定至少在版本3上。任何帮助将不胜感激,因为这使我无法完成任务!
使用from collections import Counter
(注意大写字母C)