-2
L = [98,75,92,87,89,90,92,87]
def mode(L):
shows = []
modeList = []
L.sort()
length = len(L)
for num in L:
count = L.count(num)
shows.append(count)
print 'List = ', L
maxI = shows.index(max(shows))
for i in shows:
if i == maxI:
if modeList == []:
mode = L[i]
modeList.append(mode)
print 'Mode = ', mode
elif mode not in modeList:
mode = L[i]
modeList.append(mode)
print 'Mode = ', mode
return mode
mode(L)
我似乎無法通過我的列表迭代正常...... 我能順利拿到第一模式返回>>>(模式= 87)使用第二for循環然而,我不能讓它搜索列表的其餘部分,以便它也將返回>>>(Mode = 92)查找表的模式
我已經刪除了我在Mode = 92的嘗試,你能幫忙填寫空白?
感謝
你爲什麼問同一個問題[再次](http://stackoverflow.com/questions/31364464/python-3-find -THE模式對的一列表)? – Sait