繁体   English   中英

如何找到第一个值是python中最大的列表

[英]How to find the list with the the first value is the largest in python

在这里,我有一个清单清单:

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

我想找出第一个值最大的列表,例如,在m中,我需要找出这个值[[0.5959494936867108108,820,200]]

列表按字典顺序排序,因此您的答案很简单:

>>> max(m)
[[0.5959494936867108, 820, 200]]

您可以尝试以下方法:

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])

输出:

[[0.5959494936867108, 820, 200]]

首先,您不需要双方括号; 这应该工作:

 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM