a = []
a.append([-1,-1,-1])
a.append([-1, 2, -1])
a.append([-1, -1, 3])
I want to get the maximum value of 3 in this list when there is a list. In other words
>>> max(list(map(lambda x: max(x), a)))
3
I want to do. Nesting max at this time will not work.
>>> max(max(a))
2
This is a comparison of [-1, -1, -1]
, [-1, 2, -1]
and [-1, -1, 3]
when max (a) is performed. Will be done. This is compared in lexicographic order
>>> [-1, 2, -1] > [-1, -1, 3]
True
>>> "acb" > "abz" #With this
True
This is because
>>> max(list(map(lambda x: max(x), a)))
3
>>> from itertools import chain
>>> list(chain(*a))
[-1, -1, -1, -1, 2, -1, -1, -1, 3]
>>> max(chain(*a))
3
Recommended Posts