List comprehension 多个列表中每个位置的最大值

List comprehension 多个列表中每个位置的最大值,list-comprehension,List Comprehension,我需要列出每个位置的最大值。对于L1、L2和L3,我希望得到[4、5、3、5]。以下是到目前为止我得到的信息: L1 = [1, 2, 3, 4] L2 = [4, 3, 2, 3] L3 = [0, 5, 0, 5] maxs = [] L4 = list(zip(L1,L2,L3)) print (maxs) 以下理解可以: >>> [max(tpl) for tpl in zip(L1, L2, L3)] [4, 5, 3, 5] 您还可以使用map将max函数

我需要列出每个位置的最大值。对于L1、L2和L3,我希望得到
[4、5、3、5]
。以下是到目前为止我得到的信息:

L1 = [1, 2, 3, 4]
L2 = [4, 3, 2, 3]
L3 = [0, 5, 0, 5]

maxs = []

L4 = list(zip(L1,L2,L3))

print (maxs)

以下理解可以:

>>> [max(tpl) for tpl in zip(L1, L2, L3)]
[4, 5, 3, 5]
您还可以使用
map
max
函数应用于所有压缩元组:

>>> list(map(max, zip(L1, L2, L3)))
[4, 5, 3, 5]