2 回答

TA貢獻1815條經驗 獲得超10個贊
由于您想要具有最大值的整個子列表,因此請使用 key 函數max:
def get_largest_sale(ret_data):
return max(ret_data, key=lambda sub: int(sub[2]))
>>> get_largest_sale(data)
['Joseph', 'Miller', '610300']

TA貢獻1780條經驗 獲得超1個贊
您可以定義自己的 max 函數,如下所示:
def max(list):
max=0
for i in range (len(list)):
if list[i][2]>max: //because in each of your list elements, the age is in third position
max=list[i][2]
return max
我總是喜歡重新定義事件最簡單的函數,以確保它能達到我想要的效果
[編輯]
試試這個,它應該可以工作并返回你想要的
def max(list):
max=['','',0]
for i in range (len(list)):
if list[i][2]>max[2]: //because in each of your list elements, the age is in third position
max=list[i]
return max
添加回答
舉報