Suppose I have a list [['apple', 'tree', 4, 5], ['orange', 'bush', 6, 3]]
. There isn't always 2 nested lists, could be more. I know how I would compare indexes 2 from this specific list, but lets say there's 6 nested lists.
How would I compare index 2 in all of them, and then store the list with the largest value in its second index. The point is I don't know how many lists there are and need to make it work for any amount. There is a precondition and its that the sublists are all the same length and that the second index will contain an integer.
This is a question for school so I just need help with the basic idea and not really the whole chunk of code as I don't want to plagiarize. I have made attempts, but I get index out of range error. Any help would be appreciated
temp = []
for i in range(len(lst)):
if lst[i][2] > lst[i+1][2]:
temp = lst[i]
return temp `