[英]How to find max in list of lists?
Let's say I have the following list:假设我有以下列表:
[[2016, 'May', 16.9],
[2016, 'April', 17.5],
[2016, 'March', 17.8],
[2016, 'February', 18.6],
[2016, 'January', 18.8],
[2015, 'December', 19.1],
[2015, 'November', 19.2],
[2015, 'October', 20.0],
[2015, 'September', 20.6],
[2015, 'August', 21.2],
[2015, 'July', 21.6],
[2015, 'June', 21.3],
[2015, 'May', 21.5],
[2015, 'April', 21.6],
[2015, 'March', 22.1]]
I would like to get back the list as in [2015, 'March', 22.1]
, for where the last element is the highest out of the entire list.我想找回
[2015, 'March', 22.1]
中的列表,因为最后一个元素是整个列表中最高的。
What would be a good way?什么是好方法?
Try using builtin max
function with proper lambda.尝试使用内置
max
function 和适当的 lambda。
max(data, key=lambda x: x[2])
sorted(llist, key= lambda x: x[2])[-1]
where llist is your list.其中 llist 是您的列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.