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):
More Related Contents:
- Fastest way to check if a value exists in a list
- Explanation of how nested list comprehension works?
- What exactly does the .join() method do?
- Interleave multiple lists of the same length in Python
- Compute list difference
- Custom Python list sorting
- Access item in a list of lists
- Check if all elements of a list are of the same type
- Search in lists of lists by given index
- How do I split a string into a list of characters?
- Checking if all elements in a list are unique
- TypeError: list indices must be integers or slices, not str
- Using any() and all() to check if a list contains one set of values or another
- Find min, max, and average of a list
- How to split list and pass them as separate parameter?
- Convert list into list of lists
- How to count the number of words in a sentence, ignoring numbers, punctuation and whitespace?
- Big-O of list slicing
- Repeat each item in a list a number of times specified in another list
- Adding a string to a list using augmented assignment
- Move all zeroes to the beginning of a list in Python
- Circular Reference with python lists
- convert csv file to list of dictionaries
- What is the meaning of list[:] in this code? [duplicate]
- Difference between consecutive elements in list [duplicate]
- Python list([]) and []
- Mapping dictionary value to list
- How to change variables fed into a for loop in list form
- Length of longest word in a list
- list extend() to index, inserting list elements not only to the end