I have two lists such as:
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.
My question is - what is the most pythonic way to achieve this?
Any help much appreciated.
Arguably the most readable way is
or
It will copy the lists, though, since
l_one + l_two
creates a new list. To avoid copying, you could doIf you want to select the maximum or minimum values from the two lists.I think the following will work:
It will return a maximum value after comparing each element in this two lists.
Another way that avoids copying the lists
if you just have lists like you do, this works, even with lists from different sizes :
You may even have a smarter solution which works with different numpy array :
You can combine them and then call min or max: