简体   繁体   中英

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

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"
if any(y < x for y in list):
    pass  # do something

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM