如何找到每个元组的最大值。
lst1 = [(4, 1, 9, 22, 6, 14),( 7, 22, 9, 2, 1, 2 )]
lst2 = map(max, zip(*lst1))
print(lst2)
答案 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]