您好

关注

python Counter

您好

关注

阅读 92

2023-01-20


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


相关推荐

幸福的无所谓

counter(counter attack)

幸福的无所谓 63 0 0

夏天的枫_

Python报错:NameError: name ‘Counter‘ is not defined

夏天的枫_ 260 0 0

幸甚至哉歌以咏志

python基础教程:Counter类

幸甚至哉歌以咏志 71 0 0

就是耍帅

Shared counter with Python's multiprocessing(转)

就是耍帅 66 0 0

何以至千里

Python编程:Counter计数器-dict字典的子类

何以至千里 162 0 0

上善若水的道

查看 hdfs snapshot counter 值

上善若水的道 121 0 0

沐之轻语

hadoop 计数器 Counter

沐之轻语 77 0 0

何以至千里

说说css的counter

何以至千里 87 0 0

老牛走世界

Python中使用Counter进行字典创建以及key数量统计

老牛走世界 93 0 0

Go_Viola

react笔记之完成Counter组件

Go_Viola 111 0 0

精彩评论(0)

0 0 举报