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

Ned Batchelder ned at nedbatchelder.com
Wed Sep 14 13:30:04 CEST 2011


On 9/14/2011 4:30 AM, Jacob Holm wrote:
> On 2011-09-14 05:38, Nick Coghlan wrote:
>> On Wed, Sep 14, 2011 at 12:39 PM, MRAB<python at mrabarnett.plus.com>  wrote:
>>> If none are true-ish, should it return the final (false-ish) value?
>> By analogy with 'or', yes. (and ditto for 'all' vs 'and')
>>
>>> What should any([]) return?
>> That's the more valid rationale - any()/all() need to work with an
>> empty iterable, so the most obvious solution is to limit the range to
>> True/False rather than having the result be data dependent.
>>
> The alternative would be to include a "start" parameter similar to
> sum().  It would default to False for any(), and True for all().
I don't see any need for extra parameters.  any([]) returns False, and 
all([]) returns True, just as they do now.  If you think that's an odd 
special case, I think it already is.  For example, max([]) raises a 
ValueError, so why doesn't any([])?  Don't answer that, it's just an 
illustration of how edge cases like this can be unusual.

--Ned.
>
> - Jacob
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



More information about the Python-ideas mailing list