我试图显示列表中n个最常见的项目,但出现错误:TypeError:不可散列的类型:'list'
导入集合
test = [[u'the\xa0official',u'MySQL'],[u'MySQL',u'repos'],[u'repos',u 'for'],[u'for',u'Linux'],[u'Linux',u'a'],[u'a',u'little'],[u'little',u'over '],[u'over',u'a'],[u'a',u'year'],[u'year',u'ago,'],[u'ago,',u'the '],[u'the',u'offer'],[u'offer',u'has'],[u'has',u'grown'],[u'grown',u'稳定地。\ \xa0Starting'],[稳定地\u'xa0Starting',u'off'],[u'off',u'with'],[u'with',u'support'],[u'support' ,u'for'],[u'for',u'the'],[u'the',u'Yum'],[u'Yum',u'based'],[u'based',u 'family'],[u'family',u'of\xa0Red',[u'of\xa0Red',u'Hat / Fedora / Oracle'],[u'Hat / Fedora / O racle',u'Linux,'],[u'Linux,',u'we'],[u'we',u'添加的],[u'添加的,u'Apt'],[u' Apt',u'repos'],[u'repos',u'for'],[u'for',u'Debian'],[u'Debian',u'and'],[u'and' ,u'Ubuntu'],[u'Ubuntu',u'in'],[u'in',u'late'],[u'late',u'spring,'],[u'spring,' ,u'and'],[u'and',u'throughout'],[u'throughout',u'all']]
打印测试[0]
打印类型(测试)
打印收藏集.Counter(test).most_common(3)
解决方案
>>>打印collections.Counter(map(tuple,test))。most_common(3)
[[((u'repos',u'for'),2),((u'and',u'throughout') ,1),(((u'based',u'family'),1)]