python列表的常见计算有哪些、请举例说明_计算Python列表中最常见的项目

我试图显示列表中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)]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值