【发布时间】:2014-04-30 00:31:14
【问题描述】:
我正在使用 Python 3,并且我有以下代码:
from collections import Counter
c = Counter([r[1] for r in results.items()])
但是当我运行它时,我得到了这个错误:
Traceback (most recent call last):
File "<pyshell#100>", line 1, in <module>
c = Counter([r[1] for r in results.items()])
File "C:\Python33\lib\collections\__init__.py", line 467, in __init__
self.update(iterable, **kwds)
File "C:\Python33\lib\collections\__init__.py", line 547, in update
_count_elements(self, iterable)
TypeError: unhashable type: 'list'
为什么会出现此错误?该代码最初是为 Python 2 编写的,但我在 Python 3 中使用它。Python 2 和 3 之间有什么变化吗?
【问题讨论】:
标签: python counter typeerror python-3.3