necomancer
2019-05-05 01:02:59 +08:00
l = [1,2,3,3,3,9,9,9]
l = [1,9,9,9,3,2,9,9,9]
counts = [[1,0,l[0]]]
i = 0
for idx, item in enumerate(zip(l[:-1], l[1:])):
prev, nxt = item
if prev == nxt:
counts[i][0] += 1
else:
counts.append([1,nxt,idx+1])
i += 1
print(counts, l)
print(sorted(counts, key=lambda x:(x[0],x[1],-x[2]), reverse=True)[0])
# 按出现次数、元素本身大小和元素序号(逆序)排序
print(sorted(counts, key=lambda x:(x[0],x[1],-x[2]), reverse=True)[0])
# 按出现次数、元素本身大小和元素序号排序