【发布时间】:2014-05-14 21:15:00
【问题描述】:
我有一个列表列表
list = [[1,0],[1,2],[1,1],[1,0]]
现在我想计算上述列表中类似列表元素的出现次数。
例如; [1,0]:2, [1,2]:1, [1,1]:1
我做到了
import collections
print Counter(list)
它抛出错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/collections.py", line 352, in __init__
self.update(iterable, **kwds)
File "/usr/local/lib/python2.7/collections.py", line 434, in update
self[elem] = self_get(elem, 0) + 1
TypeError: unhashable type: 'list'
我做错了什么?
【问题讨论】:
标签: python list collections