Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4801

Re: checking if a list is empty

References <BANLkTikF18n2dBU6hhFngcAPkE2ZpErVAw@mail.gmail.com>
Date 2011-05-06 00:08 -0700
Subject Re: checking if a list is empty
From Chris Rebert <clp2@rebertia.com>
Newsgroups comp.lang.python
Message-ID <mailman.1228.1304665707.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, May 5, 2011 at 11:36 PM, Jabba Laci <jabba.laci@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: checking if a list is empty Chris Rebert <clp2@rebertia.com> - 2011-05-06 00:08 -0700

csiph-web