Optimal method to find the max of sublist items within list

后端 未结 3 1273
感动是毒
感动是毒 2020-12-21 01:55

I have a multidimensional list in the format:

list = [[1, 2, 3], [2, 4, 2], [0, 1, 1]]

How do I obtain the maximum value of the third value

3条回答
  •  暖寄归人
    2020-12-21 02:28

    Just use max with a generator expression:

    >>> lst = [[1, 2, 3], [2, 4, 2], [0, 1, 1]]
    >>> max(l[2] for l in lst)
    3
    

    Also, don't name your variables list, you are shadowing the type.

提交回复
热议问题