每个元组的最大值

时间:2015-12-08 01:29:32

标签: python python-3.5

如何找到每个元组的最大值。

lst1 = [(4, 1, 9, 22, 6, 14),( 7, 22, 9, 2, 1, 2 )]
lst2 = map(max, zip(*lst1))
print(lst2)  

2 个答案:

答案 0 :(得分:1)

在Python 3中:

In [1]: lst1 = [(4, 1, 9, 22, 6, 14),( 7, 22, 9, 2, 1, 2 )]

In [8]: tuple(map(max, lst1))
Out[8]: (22, 22)

答案 1 :(得分:0)

列表理解方式是

lst2 = [max(x) for x in lst1]