How to find “maximum” value in a “List” and to extract the respective row data

Multi tool use
How to find “maximum” value in a “List” and to extract the respective row data
arr = [E1, E2, E3, E4, E5, E6]
E1 = [ 1, 2, 3, 4, 5, 6 ]
E2 = [ 10, 0.2, 23, 14, 85, 5 ]
E3 = [ 11, 21, 13, 14, 51,7 ]
E4 = [ 12, 22, 13, 24, 15,41 ]
E5 = [ 51, 26, 32, 41, 15, 65 ]
E6 = [ 11, 2, 13, 4, 15, 7 ]
max(E6) = 15
(row of the 15)
print 5, 85, 51, 15, 15, 15
Can someone please help me with this:
I have 6 lists. I want to find a maximum value in one column (one list) and to extract the respective row data (as described above).
Thanks in advance
1 Answer
1
Consider you have a list of list like this
arr = [[0, 5, 1, 2, 4, 3], [5, 4, 2, 0, 1, 3], [4, 1, 0, 3, 5, 2], [2, 1, 0, 3, 4, 5], [1, 5, 2, 0, 3, 4], [2, 1, 4, 5, 3, 0]]
To get the row on which the 6th column value is max, first sort the array in reversed order, based on 6th column and the get the first element
from operator import itemgetter
sorted(arr, key=itemgetter(5), reverse=True)[0]
# [2, 1, 0, 3, 4, 5]
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Possible duplicate of Getting the index of the returned max or min item using max()/min() on a list
– Dvorog
Jul 2 at 13:41