[Python-ideas] Break the dominance of boolean values in boolean context
Ethan Furman
ethan at stoneleaf.us
Wed Sep 14 15:12:01 CEST 2011
Ned Batchelder wrote:
> 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 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.
Perhaps 'need' is putting it too strongly, but if any()/all() were
changed to return the first true-ish/last false-ish value, then the
extra parameter would be convenient in specifying the value desired if
it wasn't True/False. Sort of like {}.get('nothere', '5').
~Ethan~
More information about the Python-ideas
mailing list