首页 找出列表中出现最频繁的数
文章
取消

找出列表中出现最频繁的数

找到列表中出现最频繁的数

1
2
3
>>> test = [1,2,3,4,2,2,3,1,4,4,4]
>>> print(max(set(test),key=test.count))
4

注:

max 函数用法

1
max(iterable, key, default)

list.count(ele) 函数用法

1
list.count(element)
本文由作者按照 CC BY 4.0 进行授权