且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在列表中查找列表的最大值,并返回单独的列表值python

更新时间:2022-02-11 08:57:22

使用 max() 函数,但通过一个参数来检查特定的索引:

Use the max() function, but pass through an argument to check a specific index:

max(inputList, key=lambda x: x[5])

这将返回inputList中具有最大索引5值的子列表.如果要实际访问此值,请在语句末尾添加[5].

This returns the sublist in inputList that has the greatest value at index 5. If you want to actually access this value, add [5] to the end of the statement.

由于似乎您希望列表的ID包含最多5个元素,因此在末尾添加[0]:

Since it seems that you want the ID of the list with the maximum 5th element, add [0] to the end:

max(inputList, key=lambda x: x[5])[0]