any(), all() and empty iterable

Peter Pearson ppearson at nowhere.invalid
Tue Apr 14 00:31:44 EDT 2009


On Sun, 12 Apr 2009 06:53:24 -0500, Tim Chase wrote:
>>>From the docs:
>> 
>> all(iterable)
>>         
>>         Return True if all elements of the iterable are true. Equivalent
>>         to:
>>         
>>         def all(iterable):
>>             for element in iterable:
>>                 if not element:
>>                     return False
>>             return True
>
> Then I'd say the comment is misleading.  An empty list has no 
> item that is true (or false), yet it returns true.  The comment 
> in the docs should read "Return False if any element of the 
> iterable is not true" or "Return True if all elements of the 
> iterable are true or if the iterable is empty."

How 'bout: "Return True if no element of the iterable is not true"?

-- 
To email me, substitute nowhere->spamcop, invalid->net.



More information about the Python-list mailing list