python Counter

来源:互联网 发布:手机凤凰卫视直播软件 编辑:程序博客网 时间:2024/06/15 04:23
from collections import Countera=[1,2,3,3,3,3,3,5,6,7,7,7,8,8]Counter(a)
Counter({1: 1, 2: 1, 3: 5, 5: 1, 6: 1, 7: 3, 8: 2})
mostn=Counter(a).most_common(2)
mostnOut[185]: [(3, 5), (7, 3)]
mostn[0][0]Out[186]: 3mostn[0][1]Out[187]: 5mostn[1][0]Out[188]: 7mostn[1][1]Out[189]: 3
原创粉丝点击