transformation
all()
Returns True if every element of the iterable is truthy (or if the iterable is empty). Short-circuits on the first falsy value.
all(iterable) Parameters
| Parameter | Purpose |
|---|---|
| iterable | Iterable of values tested for truthiness |
| returns | True if every element truthy; True for an empty iterable (vacuous) |
Examples
all([1, 2, 3]) Returns True
all([1, 0, 3]) Returns False (0 is falsy)
all([]) Returns True (vacuous truth)
all(isinstance(x, int) for x in [1, 2, 3]) Returns True
Gotcha
all([]) returns True (vacuous truth) — a common source of bugs when the collection was expected to be non-empty.
Related built-ins
any()
Returns True if any element of the iterable is truthy. Short-circuits on the first truthy 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.