Work with list of lists of tuples

I have this list:

dCF3v=[[(1.90689635276794, -44704.76171875)],
       [(1.90689635276794, -44705.76171875)],
       [(1.90689635276794, -44706.76171875)],
       [(1.90689635276794, -44707.76171875)]
      ]

I'd like to compare the second element of each tuple and find the absolute maximum:

-44707.76171875

My code looks like:

CF3=0
for x in dCF3v:
    if abs(x[1])>abs(CF3):
        CF3=x[1]

Answers


You have a list which holds lists which hold a tuple. So, you probably want abs(x[0][1]). Then you command can simply be:

max(abs(x[0][1]) for x in dCF3v)

More to the point, you probably actually want to change the data structure to a list holding tuples:

dCF3v = [x[0] for x in dCF3v]

which then would look like:

max(abs(x[0]) for x in dCF3v)

Or, if you wanted the entire tuple to be returned instead of just the second element:

max(dCF3v,key=lambda x:abs(x[0]))

Need Your Help

Moq and accessing called parameters

unit-testing design-patterns moq oop xunit.net

I've just started to implement unit tests (using xUnit and Moq) on an already established project of mine. The project extensively uses dependency injection via the unity container.

git frontend function(ality) for smart http git in php?

php git apache gitolite

I am busy installing gitolite3 with smart http. Gitolite3, essentially, is just a bunch of scripts that relay requests back to the git-http-backend (i think), and calls all sorts of hooks

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.