已知两个列表,找到两个列表合并后的中位数。

ls1=[15,48,1,1564,86]
ls2=[4,578,54,158,41,545,46,8,41]

ls1+=ls2
ls1=sorted(ls1)
print(ls1)
mi=len(ls1)/2
if len(ls1)%2:
    print((ls1[int(mi)]))
else:
    print((ls1[int(mi)-1]+ls1[int(mi)])/2)

猜你喜欢

转载自blog.csdn.net/qq_27900321/article/details/130239161