On Mon, Apr 20, 2009 at 1:54 AM, Gerhard Häring <g...@ghaering.de> wrote:
> Peter Otten wrote:
>> bdb112 wrote:
>>
>>> Your explanation of Boolean ops on lists was clear.
>>> It leads to some intriguing results:
>>>
>>> bool([False])
>>> --> True
>>>
>>> I wonder if python 3 changes any of this?
>>
>> No. Tests like
>>
>> if items:
>>    ...
>>
>> to verify that items is a non-empty list are a widespread idiom in Python.
>> They rely on the behaviour you observe.
>
> Are they widespread? I haven't noticed, yet.
>
> I prefer to write it explicitly:
>
> if len(lst) > 0:

Nope, that's not idiomatic. The simpler `if lst:` version is indeed widespread.

>    ...
>
> if item is None:

That's pretty common and accepted; comparison to None is something of
a special case.

Cheers,
Chris
-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to