找出出现次数最多的数字 并输出次数
找出出现次数最多的数字 并输出次数
题目:一维数组 都是数字 找出出现次数最多的数字 并输出次数
出现次数相同的话 输出值比较大的那个数字
例子:
strInput = [4,4,9,4,9,9,1]
counts = {}#定义一个字典为了方便储存
for i in strInput:
counts[i] = strInput.count(i)#获得所有数字对应的出现次数
resultList = sorted(list(counts.items()),key= lambda x:(x1,x[0]),re
原创
2021-01-20 23:29:34 ·
2660 阅读 ·
0 评论