Get min value based on condition

Issue

I have the following list

L= [383, 590, 912, 618, 203, 982, 364, 131, 343, 202]

If I use the function min(L) I get 131

Is it possible to know the min value in the list of numbers that exceed 200?
I guess something like min(L, Key>200)

The desired result would be 202

Solution

You can use the min() function in combination with a list traversal using a for loop as follows to introduce conditions when finding minimums:

L= [383, 590, 912, 618, 203, 982, 364, 131, 343, 202]
m = min(i for i in L if i > 200)
print(m)

Output:

202

Answered By – Cardstdani

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published