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

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu Sep 15 15:40:50 CEST 2011

On Thu, Sep 15, 2011 at 8:30 AM, Sven Marnach <sven at marnach.net> wrote:
> MRAB schrieb am Mi, 14. Sep 2011, um 18:19:45 +0100:
>> I had a use-case recently.
>> I was looking for an entry in a pseudo-dict, where the key didn't have
>> to be an exact match, so I called the .get method on the pseudo-dict
>> until it returned a true-ish value (the value would never be false-ish).
>> I just wrote a short function to do what I wanted.
> FWIW, I just came to python-ideas to propose the same change to any()
> for the same use case (look-up in a pseudo dict).  I needed this
> several times now, and I would consider the change to any()
> worthwhile.  (For consistency, all() would also have to be changed,
> though I didn't have a use case yet.)

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

More information about the Python-ideas mailing list