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

Bill Janssen janssen at parc.com
Thu Sep 15 19:13:46 CEST 2011


Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:

> As someone suggested earlier in this thread, this can be achieved with
> a very simple expression (not even a function!):
> 
> next(filter(None, S))
> 
> will return the first item x from S with bool(x) evaluating to True.
> Further simplifying this is not worth slowing down all current uses of
> any().

Yeah, but you've got to think up that expression.  I agree that slowing
down any() is not a good thing, but there's surely a place for this
functionality -- probably more useful than any() itself.  I've wished
several times that any() just returned the first hit.  Personally, I'd
add a function some() that either returns a matching value or raises an
exception.

Bill



More information about the Python-ideas mailing list