Find every index of max value in a column in two-dimensional list

So I made this function to find what the max value of "column" is in my 2d-list, which returns the max value of my said column in my list, but this said max value actually appears twice, so how do I return the indexes/rows where this max value appears?

Cheers

def find_max(column):
    maxVal = 0
    for i in range(1, len(lst)):
        maxVal = max(maxVal, int(lst[i][column]))
    return (maxVal) 

I feel so lost, but i've been trying something like this.... v (obv not working atm, just brainstorming)


def test(column):
    maxVal = 0
    year = []
    for i in range(1, len(lst)):
        if maxVal == int(lst[i][column]):
            year.append(lst[i][0])
        else:
            maxVal = max(maxVal, int(lst[i][column]))
            year = (lst[i][0])
        year.extend(maxVal)
    return year

#so column 0 is years, and I want to save the years where my X column had the biggest value(s). 

Edit: My list looks like this

And lets say the column I'm looking for is the third (or index 2), so I have the max value of 27 on row 36 & 38, how do I return these indexes? (What im actually looking for is what the value on first column is, 2004 & 2006)



Read more here: https://stackoverflow.com/questions/64940150/find-every-index-of-max-value-in-a-column-in-two-dimensional-list

Content Attribution

This content was originally published by Fribbe at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: