What is the most efficient way to test for False in a list?
John J. Lee
jjl at pobox.com
Tue Jul 10 19:36:18 EDT 2007
Duncan Booth <duncan.booth at invalid.invalid> writes:
> Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:
>
>> "Diez B. Roggisch" <deets at nospam.web.de> writes:
>>> >> 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.
>>
>> all(list) does what the OP's code did, tests for the presence of a
>> false value in the list. If you want an identity test, use
>>
>> status = not (False in list)
>
> That is an equality test, not an identity test:
>
>>>> False in [0]
> True
It's also not a very idiomatic equality test -- "x not in y" is better
than "not (x in y)".
John
More information about the Python-list
mailing list