Get max value from a list with lists?

前端 未结 7 557
南笙
南笙 2020-12-09 11:32

So I have a list that contains several list which all have three strings first, then one float number, like:

resultlist = [[\"1\", \"1\", \"a\", 8.3931], [\         


        
7条回答
  •  没有蜡笔的小新
    2020-12-09 12:06

    Numpy helps with numerical nested lists. Try this:

    resultlist = [[3, 2, 4, 4], [1, 6, 7, -6], [5, 4, 3, 2]]
    max(resultlist)  # yields [5, 4, 3, 2] because 5 is the max in: 3, 1, 5
    np.max(resultlist)  # yields 7 because it's the absolute max
    

    max() returns the list which first element is the maximum of all lists' first element, while np.max() returns the highest value from all the nested lists.

提交回复
热议问题