Pythonic way of checking if a condition holds for any element of a list

any():

if any(t < 0 for t in x):
    # do something

Also, if you’re going to use “True in …”, make it a generator expression so it doesn’t take O(n) memory:

if True in (t < 0 for t in x):

Leave a Comment