a=[1,6,7,4,4,5,4,5,4,5,5,6,7,8,5,6,7,3,4,2,2,1,4,8,9,4,5,6,12,12,13,14]
'''
需求:给定一个只包含正整数且非空的数组,返回该数组中重复次数最多的前N个数字(返回结果按重复次数从多到少降序排列,N不存在取值非法的情况)
'''
def get_datas(a):
result = []
data_dect = {}
#将键值对按值(数字出现的次数)排序 -- 从高到低排序
for itemin set(a):#set
data_dect[str(item)] = a.count(item)
res =sorted(data_dect.values(),reverse=True)#对重复次数降序
print(res)
for num in res:
# data_dect.items()是将字典转换成可遍历的元组
for key,value in data_dect.items():
if num ==value and key not in result:
result.append(key)
return result
print("====",get_datas(a))