checking if a list is empty

Terry Reedy tjreedy at udel.edu
Fri May 6 15:31:57 EDT 2011


On 5/6/2011 7:34 AM, James Mills wrote:
> On Fri, May 6, 2011 at 4:36 PM, Jabba Laci<jabba.laci at gmail.com>  wrote:
>> If I want to check if a list is empty, which is the more pythonic way?
>
> [...]
>
>> (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.

-- 
Terry Jan Reedy




More information about the Python-list mailing list