any(), all() and empty iterable

Antoon Pardon apardon at forel.vub.ac.be
Mon Apr 20 08:26:09 EDT 2009


On 2009-04-15, John O'Hagan <mail at johnohagan.com> wrote:
> On Tue, 14 Apr 2009, Mark Dickinson wrote:
>> On Apr 14, 7:21 pm, Luis Alberto Zarrabeitia Gomez <ky... at uh.cu>
>>
>> wrote:
>> > It's more than that. Python's following the rules here. Maybe it could be
>> > documented better, for those without a background in logic/discrete
>> > mathematics, but not changed.
>>
>> Agreed.
>>
>> I'd like to guess that in 93.7% of cases, when a programmer
>> has used all(seq) without having thought in advance about what the
>> right thing to do is when seq is empty, the current behaviour is
>> already the right one.  I tried to test this hypothesis, but a
>> Google code search for uses of all() turned up very little
>> besides definitions.  For example:
>>
>> if all(t.already_filed() for t in my_tax_forms):
>>     go_to_bed_happy()
>> else:
>>     file_for_extension()
>
>
> But what about this:
> 	
> if all(evidence):
> 	suspect_is_guilty
> else:
> 	suspect_is_innocent

even if the evidence is not empty, the above wouldn't be
a good test, because you need enough evidence en enough
is not implied by all even if all is more than nothing.

-- 
Antoon.



More information about the Python-list mailing list