What is the most efficient way to test for False in a list?

Diez B. Roggisch deets at nospam.web.de
Mon Jul 9 07:19:28 EDT 2007


Bjoern Schliessmann wrote:

> Paul Rubin wrote:
>> lex <alexander.somma at gmail.com> writes:
> 
>>> list = [1, True, True, False, False, True]
>>> status = True
>>> for each in list:
>>>     status = status and each
>>> 
>>> but what is your best way to test for for False in a list?
>> 
>> status = all(list)
> 
> Am I mistaken, or is this no identity test for False at all?

You are mistaken. all take an iterable and returns if each value of it is
true.

Diez



More information about the Python-list mailing list