Use map() to return the largest element of each pair (tuple) in the list below: pairs = [(7,5),(1,2),(5,2),(9,1),(4,7)]
时间: 2023-10-08 10:07:58 浏览: 60
从两个数组中找最大元素
Sure, here's the code to use map() to return the largest element of each pair (tuple) in the given list:
```python
pairs = [(7,5),(1,2),(5,2),(9,1),(4,7)]
result = list(map(lambda x: max(x), pairs))
print(result)
```
Output:
```
[7, 2, 5, 9, 7]
```
Here, we have used the `max()` function with `lambda` function to find the maximum element in each tuple of the list. Then, we have converted the result into a list using the `list()` function. Finally, we have printed the result.
阅读全文