python_fan
python_fan

Reputation: 15

Max of each tuple

How do I find the max for each tuple.

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

Upvotes: 0

Views: 37

Answers (2)

Hooting
Hooting

Reputation: 1711

a list comprehension way is

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

Upvotes: 0

Akavall
Akavall

Reputation: 86326

In 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)

Upvotes: 1

Related Questions