Skip to content

Latest commit

 

History

History
25 lines (18 loc) · 439 Bytes

67.md

File metadata and controls

25 lines (18 loc) · 439 Bytes
@author jackzhenguo
@desc 
@date 2019/4/6

67 求众数

def top1(lst):
    return max(lst, default='列表为空', key=lambda v: lst.count(v))

测试举例:

lst = [1, 3, 3, 2, 1, 1, 2]
r = top1(lst)
print(f'{lst}中出现次数最多的元素为:{r}')  
# [1, 3, 3, 2, 1, 1, 2]中出现次数最多的元素为:1
[上一个例子](66.md) [下一个例子](68.md)