【问题标题】:Python 3.0.1 collections.CounterPython 3.0.1 集合.计数器
【发布时间】:2012-04-05 20:12:11
【问题描述】:

在 Python 3.0.1 中,我试图使用 collections 模块的 Counter 部分 我在文档中的任何地方都没有说模块的这一部分在 Python 3.0.1 中不可用。但是……

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

我的所有 yield 错误...为什么会这样???

【问题讨论】:

    标签: python collections python-3.x counter


    【解决方案1】:

    collections.Counter 是在 3.1 版中添加的。要么升级到 3.2,要么自己实现类。有食谱here.

    【讨论】:

    • 该配方似乎是为 Python 2.x 编写的,如果您在 Python 3.0 中使用它,则需要将所有 iteritems 函数引用替换为 items
    【解决方案2】:

    使用 3.0——它在到达时基本上已经死了,因为它有严重的问题。获得 3.2,或至少 3.1。

    【讨论】:

      【解决方案3】:

      Counter 类在 python 的 3.0.1 版本中不存在。它出现在 3.1 版本中。

      【讨论】:

        【解决方案4】:

        3.0.1 的手册中没有出现计数器:http://docs.python.org/release/3.0.1/library/collections.html

        它似乎首先出现在 3.1 中: http://docs.python.org/release/3.1/library/collections.html

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-10-29
          • 1970-01-01
          • 1970-01-01
          • 2015-04-08
          • 1970-01-01
          • 2017-03-08
          • 2018-01-15
          • 2019-05-07
          相关资源
          最近更新 更多