python - Index of row where maximum value is located -


i have list:

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

i'd know index of row maximum value is. in example above: row index 3.

i have code finding maximum value:

cf3a = (abs(x[0][1]) x in dcf3v) cf3 = max(cf3a) 

if possible i'd adapt code , not have classic for , if loops.

you can use enumerate keep indices , key argument max right value:

dcf3v=[[(1.90689635276794, -44704.76171875)],        [(1.90689635276794, -44705.76171875)],        [(1.90689635276794, -44706.76171875)],        [(1.90689635276794, -44707.76171875)]       ]  cf3a = (abs(x[0][1]) x in dcf3v) index, value = max(enumerate(cf3a), key=lambda (index, value): value) print index,value 

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 -