import numpy as np
def mysort(data):
for i in range(len(data)):
for j in range(len(data)-1):
if data[j]<data[j+1]:
data[j],data[j+1] = data[j+1],data[j]
return data
def find_max(datas):
new_datas = mysort(datas)
singl = new_datas[0]
count = 0
max_count = 0
for data in new_datas:
if data == singl:
count += 1
if count > max_count:
max_count = count
max_num_data = singl
else:
count = 1
singl = data
print(data,singl,count)
return max_num_data,max_count
mylist = [3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,2,1,1,1,1,1,1,1,1,1]
new_list = find_max(mylist)
print(new_list)
输出数组中最多的元素以数量(python)
最新推荐文章于 2024-10-30 16:52:22 发布