checking if a list is empty

Chris Rebert clp2 at rebertia.com
Fri May 6 03:08:24 EDT 2011


On Thu, May 5, 2011 at 11:36 PM, Jabba Laci <jabba.laci at gmail.com> wrote:
> Hi,
>
> If I want to check if a list is empty, which is the more pythonic way?

Option (2), IMO.

> li = []
>
> (1) if len(li) == 0:
> ...

FYI, also equivalent:
if not len(li):
    ...

> or
> (2) if not li:

Cheers,
Chris



More information about the Python-list mailing list