所以我本质上有一个 2 维和 1/2 维矩阵,我想从列表中的列表返回一个元素。
def somefunc(x):
# What I want to do is return the max element within a matrix based on l[:][1]
return j
# example
l = [[[1,2,3],4],
[[5,6,7],8],
[[9,1,2],3]]
>>>somefunc(l)
[[5,6,7],8]
最佳答案
在 max()
函数中使用 key
参数。
def somefunc(x):
return max(x, key=lambda e: e[1])
关于python - 如何在列表中返回列表的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41856742/