I know the title is bit hard to understand. Sorry for that, let me explain. for example: we have a nested list consist of 4 lists each with 3 elements, the first two are strings(not char) and the third one is an int:
LLList = [ ["A", "B", 30], ["C", "B", 30], ["D", "B", 20], ["D", "L", 60] ]
I want to count the number or return all indexes of elements in the "LLList" (elements in the "LLList" are the triple-element lists like ["A", "B", 30]) where the third element is greatest where the second element is "B".
A naive way would be to find all elements whose second elements is "B" and put it in a list. in this case would be:
TempList = []
for w in LLList
if w[1] == "B"
TempList.append(w)
The result would be:
TempList = [ ["A", "B", 30], ["C", "B", 30], ["D", "B", 20] ]
Then find the max value among the 3rd elements in TempList in this case would be 30
MaxB = max(TempList, key = lambda x:x[2])[2] # MaxB = 30
And count the occurrence of MaxB in the 3rd column of TempList
[p[2] for p in TempList].count(MaxB)
In this case would be 2
This is a overly naive method, too much to code, need too much RAM and time to complete, I know it, but I cannot think of anything better than this. I know there must be an elegant and effective way to solve this problem, please help me, thank you very much!