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

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -

collision detection - C++ library for mesh to mesh intersection: what is available? -