Python取出数组中重复次数最多的数

def max_list(lt):
    temp = 0
    for i in lt:
        if lt.count(i) > temp:
            max_ele = i
            temp = lt.count(i)
    return "重复次数最多元素为%s,重复次数为%d次" % (max_ele, temp)

n = ['a','b','a','c','d','a']
print(max_list(n))

重复次数最多元素为a,重复次数为3次

  

posted @ 2022-05-29 11:50  lucky_tomato  阅读(1123)  评论(0编辑  收藏  举报