from collections import Counter
from itertools import groupby
l = [1,2,7,7,8,9,9]
freqs = groupby(Counter(l).most_common(), lambda x:x[1])
print [val for val,count in freqs.next()[1]]
这是用于查找多种模式的代码,但我一直在收到错误
Traceback (most recent call last):
File "G:\Documents\summative.py", line 30, in -toplevel-
from collections import Counter
ImportError: cannot import name Counter
有办法解决这个问题吗?
答案 0 :(得分:1)
Counter
未添加到Python collections
模块中。 Raymond Hettinger有一个ActiveState Cookbook recipe可用于2.5或更高版本。