Python - 2d list max based on certain part of inner list

So I have a 2-dimensional list (as in a list of lists) and I'm trying to find the largets inner list based on their third element.

This is what I have so far, but it only returns j[2], not the entire list j where j[2] is the biggest.

big = max([int(j[2]) for j in cur2])

What I want it to do is return the entire max list out of each of the lists inside of cur2 dependent on the size of int(j[2])

Please don't refer to this question because I don't really understand how to apply that answer to my situation.

Answers


Try this:

max( cur2, key=lambda x:int(x[2]))

Example:

>>> cur2=[range(4),range(4,8),range(2,6)]
>>> cur2
[[0, 1, 2, 3], [4, 5, 6, 7], [2, 3, 4, 5]]
>>> max( cur2, key=lambda x:int(x[2]))
[4, 5, 6, 7]

Need Your Help

Error in calling php file in table data using Ajax

javascript php html ajax

I have small project in which i have different news.I have to include this news_all.php file in table data in the dashboard.php file. I have predefined root structure in which i cannot use

defering n:m lookup to stored procedure

sql-server database-design stored-procedures

I have a set of objects which can be members of one or more of a low number of sets (think objects which can sit in several positions inside a tree). Since these assignments need to be queried ofte...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.