Python查找分钟&最多两个列表 [英] Python find min & max of two lists

查看:73
本文介绍了Python查找分钟&最多两个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表,例如:

l_one = [2,5,7,9,3]
l_two = [4,6,9,11,4]

...并且我需要从两个列表中找到最小值和最大值.也就是说,我要生成一个最小值和一个最大值.

...and I need to find the min and max value from both lists combined. That is, I want to generate a single min and a single max value.

我的问题是-实现这一目标的最pythonic方法是什么?

My question is - what is the most pythonic way to achieve this?

非常感谢您的帮助.

推荐答案

可以说,最易读的方式是

Arguably the most readable way is

max(l_one + l_two)

min(l_one + l_two)

但是,由于l_one + l_two创建了一个新列表,它将复制列表.为避免复制,您可以

It will copy the lists, though, since l_one + l_two creates a new list. To avoid copying, you could do

max(max(l_one), max(l_two))
min(min(l_one), min(l_two))

这篇关于Python查找分钟&最多两个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆