编写程序求出多个列表中的最大值、最小值和元素个数。(要求:函数调用,并以元组作为返回值)
时间: 2023-05-15 09:06:40 浏览: 57
可以使用以下代码实现:
```python
def get_max_min_count(*lists):
max_values = []
min_values = []
counts = []
for lst in lists:
max_values.append(max(lst))
min_values.append(min(lst))
counts.append(len(lst))
return max_values, min_values, counts
```
这个函数接受任意数量的列表作为参数,并返回一个元组,其中包含所有列表的最大值、最小值和元素个数。例如,如果我们有以下三个列表:
```python
list1 = [1, 2, 3, 4, 5]
list2 = [10, 20, 30, 40, 50]
list3 = [-1, -2, -3, -4, -5]
```
我们可以调用这个函数来获取它们的最大值、最小值和元素个数:
```python
max_values, min_values, counts = get_max_min_count(list1, list2, list3)
print("Max values:", max_values)
print("Min values:", min_values)
print("Counts:", counts)
```
这将输出:
```
Max values: [5, 50, -1]
Min values: [1, 10, -5]
Counts: [5, 5, 5]
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![flv](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)