transformation
any()
Returns True if any element of the iterable is truthy. Short-circuits on the first truthy value.
any(iterable) Parameters
| Parameter | Purpose |
|---|---|
| iterable | Iterable of values tested for truthiness |
| returns | True if any element truthy; False for an empty iterable |
Examples
any([0, '', False, 1]) Returns True
any([0, '', None]) Returns False
any(x > 10 for x in [1, 5, 20]) Returns True (short-circuits at 20)
Gotcha
any([]) returns False, not True. Combine with a generator expression for lazy predicate checking.
Related built-ins
all()
Returns True if every element of the iterable is truthy (or if the iterable is empty). Short-circuits on the first falsy value.
filter()
Yields items from iterable for which function(item) is truthy. If function is None, filters out falsy items.
sum()
Sums the items of an iterable, adding them to start. Optimized for numbers.
sorted()
Returns a new sorted list from any iterable. Uses Timsort — stable, O(n log n).
min()
Returns the smallest item in an iterable or the smallest of two or more arguments. Supports a key function for custom comparison.