python - Work with list of lists of tuples -


i have list:

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

i'd compare second element of each tuple , find absolute maximum:

-44707.76171875 

my code looks like:

cf3=0 x in dcf3v:     if abs(x[1])>abs(cf3):         cf3=x[1] 

you have list holds lists hold tuple. so, want abs(x[0][1]).
command can be:

max(abs(x[0][1]) x in dcf3v) 

more point, actually want change data structure list holding tuples:

dcf3v = [x[0] x in dcf3v] 

which like:

max(abs(x[0]) x in dcf3v) 

or, if wanted entire tuple returned instead of second element:

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

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -