python返回列表中出现次数最多的数
生活随笔
收集整理的這篇文章主要介紹了
python返回列表中出现次数最多的数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
def majorityCnt(classList):'''返回標簽列表中最多的標簽'''count_dict = {}for label in classList:if label not in count_dict.keys():count_dict[label] = 0count_dict[label] += 1# print(count_dict)return max(zip(count_dict.values(), count_dict.keys()))[1]
總結
以上是生活随笔為你收集整理的python返回列表中出现次数最多的数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python求阶乘和
- 下一篇: python不定长参数详解