0

Here i have a list of lists:

m = [[[0.5898237279659958, 620, 200]],[[0.58557319664958118, 720, 200]],[[0.5959494936867108, 820, 200]], [[0.59444930616327041, 920, 200]]]

I would like to find out the list which first value is the largest, for example, in m, i need to find out this [[0.5959494936867108, 820, 200]]

1
  • this task/question was answered many-many times on SO ... it remains to only find already working solution Commented Oct 19, 2017 at 17:08

3 Answers 3

3

Lists are sorted lexicographically, so your answer is simply:

>>> max(m)
[[0.5959494936867108, 820, 200]]
Sign up to request clarification or add additional context in comments.

Comments

1

You can try this:

m = [[[0.5898237279659958, 620, 200]],[[0.58557319664958118, 720, 200]],[[0.5959494936867108, 820, 200]], [[0.59444930616327041, 920, 200]]]
final_m = max(m, key=lambda x:x[0])

Output:

[[0.5959494936867108, 820, 200]]

Comments

0

first of all, you don't need the double square brackets; this should work:

 m = [[0.5898237279659958, 620, 200],[0.58557319664958118, 720, 200], [0.5959494936867108, 820, 200], [0.59444930616327041, 920, 200]]
        nums = []
        for l in m:
            nums.append(l[0]) #Puts the first value of each list into a list, 
                              #0 can be changed to position in the list you want
        nums.sort() #Puts the largest value last
        cornum = nums[-1] #Gets the last number
        for l in m:
            if cornum in l: #checks if the number is in each of the lists in m
                print(l)

1 Comment

It is a bit longer than the others, but it allows you to get the list with the highest list[x] value, where x can be anything