[Python-ideas] Break the dominance of boolean values in boolean context

MRAB python at mrabarnett.plus.com
Thu Sep 15 01:25:09 CEST 2011


On 15/09/2011 00:15, Greg Ewing wrote:
> Steven D'Aprano wrote:
>
>> I don't see that. next() returns the next item from an iterator
>> regardless of its boolean state. The actual and proposed
>> implementations of any() skip over false items.
>
> While such a function might be useful, I think it would be
> better provided as a new function called something like
> first(), rather than changing any().
>
Could it also have something like a 'key' argument, by default
__bool__? It would return the first item for which key(item) returns
True or something true-ish.

There's also the option of a 'default' argument for when there are no
true-ish items.



More information about the Python-ideas mailing list