Python - detecting values in a list -
this question has answer here:
how detect if value held in list negative, need find out if there value negative, far have this:
if list[range(list)] < 0
but surely detect if values in list negative.how go doing this?
also, how able detect if value in list not integer, example floating point number, or character
thanks
you can use any
function, this
if any(item < 0 item in my_list):
for example,
print any(item < 0 item in [0, 1, 2]) # false print any(item < 0 item in [0, 1, -2]) # true
we use generator expression in any
function. returns true
, if of item
lesser 0.
Comments
Post a Comment