checking if a list is empty
harrismh777
harrismh777 at charter.net
Fri May 6 15:49:24 EDT 2011
Terry Reedy wrote:
>>> (2) if not li:
>>
>> This is fine.
>
> This is the intended way. Anything in addition is extra noise and wasted
> calculation. In other words, let Python do the boilerplate work for you.
I agree, but I don't like it.
... if not li says nothing about what li is supposed to 'be' and
implies in any case that li does not exist, or worse is some kind of
boolean.
li is in fact an empty list [] and will identify as such, and of
course (as a list object) has all of the attributes and methods of a list...
Why not have a list method that makes this more explicit:
if not li.emptylist()
if not li.empty([])
there might be others...
kind regards,
m harris
More information about the Python-list
mailing list