Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

What would be a good way?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try using builtin max function with proper lambda.

max(data, key=lambda x: x[2])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading