I have a list of lists
list_of_lists = [['a',1,19,5]['b',2,4,6],['c',22,5,9],['d',12,19,20]]
and I'd like to get the top x lists with the highest values so
top 3 max(list_of_lists)
would return
[['c',22, 5,9],['d',12,19,20],['a',1,19,5]]
or if I'm looping through list_of_lists
I could append each of the lists with the top x max values to another list of lists, based upon the index of the selected lists.
Here's the code I'm working with but it's flawed as I think I need to delete the selected answer at the end of each loop so it doesn't appear in the next loop and it only looks at column 4 (x[3])
for y in case_list:
last_indices = [x[3] for x in case_list]
print("max of cases is: ",max(last_indices))
And the output of that is currently:
max of cases is: 22
max of cases is: 22
max of cases is: 22
This answer gives the top max list but I would like to have the flexibility to return the top x rather than just one.
This answer gives the top x max values in a single list.