python Counter

from collections import Counter
a=[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)
mostn
Out[185]: [(3, 5), (7, 3)]
mostn[0][0]
Out[186]: 3

mostn[0][1]
Out[187]: 5

mostn[1][0]
Out[188]: 7

mostn[1][1]
Out[189]: 3
posted @ 2022-08-19 22:59  luoganttcc  阅读(18)  评论(0编辑  收藏  举报