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


Groups > comp.lang.python > #4801 > unrolled thread

Re: checking if a list is empty

Started byChris Rebert <clp2@rebertia.com>
First post2011-05-06 00:08 -0700
Last post2011-05-06 00:08 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#4801 — Re: checking if a list is empty

FromChris Rebert <clp2@rebertia.com>
Date2011-05-06 00:08 -0700
SubjectRe: checking if a list is empty
Message-ID<mailman.1228.1304665707.9059.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web