Reputation: 81
So I essentially have a 2 and 1/2 dimensional matrix and I want to return an element from a list within a list.
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]
Upvotes: 1
Views: 66
Reputation: 4925
Use key
parameter in max()
function.
def somefunc(x):
return max(x, key=lambda e: e[1])
Upvotes: 3