Enzo Vidal
Enzo Vidal

Reputation: 249

Check if an item is in the list

I'm a newbie in python. I am making a script that will check if an item on the list is on a particular range, it will do some commands. and I have no idea how to make one. Im thinking of using an IF statement, but I think I'm wrong.

What I have in mind is something like:

list = [list of values]
if ( an entry on a list is lower than x): #given that x is any number
    do this

Upvotes: 1

Views: 103

Answers (2)

unwind
unwind

Reputation: 399713

You can use min() on the list to return the smallest value. Thus:

if thelist and min(thelist) < x:
  print "There's something small in the list"

Upvotes: 2

Chris Martin
Chris Martin

Reputation: 30736

if any(y < x for y in list):
    pass  # do something

Upvotes: 0

Related Questions