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


Groups > comp.lang.python > #4979

Re: checking if a list is empty

References (4 earlier) <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <Aqoxp.67882$7N3.65130@newsfe10.iad> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> <YfJxp.23215$vT3.14206@newsfe06.iad> <BANLkTi=Et3i2EWHwyvRzAh9E4Z-O+Rz9Sg@mail.gmail.com>
From James Mills <prologic@shortcircuit.net.au>
Date 2011-05-09 14:46 +1000
Subject Re: checking if a list is empty
Newsgroups comp.lang.python
Message-ID <mailman.1322.1304916448.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, May 9, 2011 at 2:34 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> "bool(list)" describes whether the list contains something.  "Not"
> being a logical operator, it stands to reason that "not list" should
> mean the same thing as "not bool(list)".  Anything else would be
> surprising and pointlessly convoluted.  If "not list" bothers you,
> then I would suggest that your problem is actually with "bool(list)".

I concur! +1

>>        ...  should return True only if 'list' is bound to NULL, or if the
>> name 'list' would throw a name exception...

[...]

>>        ...  and, Python should have an explicit way of testing for an empty
>> list that is clear, concise, and easy to understand even for the relatively
>> new Python programmer.  This is not intended to generate counter argument,
>> its just my feedback on a language construct that I find to be inconsistent
>> logically. ... Please, no pedantic discourse explaining why I'm wrong...
>> just put in into a PEP and move on.  :)
>
> It does.  "if len(list) == 0"

Again +1 on the if len(list) == 0:

Now... One thing that really concerns me about the Python
community as a whole is the no. of varying opinions of
"correct" ways of doing things and the distaste for a lot of
things (which in Python are just obvious).

If you are an opinionated individuals and disagree with the
suggestion (even if it is "right"), perhaps keep that to yourself.

if not my_list:

is a perfectly valid and fine idiom to use in Python.

If you prefer some other way, that's fine. Quite frankly
I'm sick of seeing posts that argue for the sake of arguing.

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"

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


Thread

Re: checking if a list is empty Terry Reedy <tjreedy@udel.edu> - 2011-05-06 15:31 -0400
  Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-06 14:49 -0500
    Re: checking if a list is empty Adam Tauno Williams <awilliam@whitemice.org> - 2011-05-06 16:05 -0400
      Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-07 02:49 +0000
        Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-11 10:14 +0100
          Re: checking if a list is empty Laurent Claessens <moky.math@gmail.com> - 2011-05-11 11:48 +0200
            Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-11 11:14 +0000
              Re: checking if a list is empty Laurent Claessens <moky.math@gmail.com> - 2011-05-11 13:45 +0200
              Re: checking if a list is empty Laurent Claessens <moky.math@gmail.com> - 2011-05-11 13:45 +0200
          Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-11 13:36 +0000
            Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-11 15:00 +0100
              Re: checking if a list is empty Chris Angelico <rosuav@gmail.com> - 2011-05-12 00:46 +1000
              Re: checking if a list is empty Ethan Furman <ethan@stoneleaf.us> - 2011-05-11 08:53 -0700
              RE: checking if a list is empty "Prasad, Ramit" <ramit.prasad@jpmchase.com> - 2011-05-11 13:50 -0400
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-11 19:15 +0100
                RE: checking if a list is empty "Prasad, Ramit" <ramit.prasad@jpmchase.com> - 2011-05-11 14:59 -0400
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-11 20:08 +0100
                Re: checking if a list is empty Ethan Furman <ethan@stoneleaf.us> - 2011-05-11 12:17 -0700
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-11 20:13 +0100
                Re: checking if a list is empty Ian <hobson42@gmail.com> - 2011-05-11 22:02 +0100
                Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-11 21:47 +0000
                Re: checking if a list is empty Steven Howe <howe.steven@gmail.com> - 2011-05-11 15:09 -0700
                Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-11 17:38 -0500
                Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-11 18:12 -0500
                Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-12 01:07 +0000
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-12 06:21 +0100
                Re: checking if a list is empty Chris Angelico <rosuav@gmail.com> - 2011-05-12 13:51 +1000
                Re: checking if a list is empty Ethan Furman <ethan@stoneleaf.us> - 2011-05-12 07:02 -0700
                Re: checking if a list is empty Chris Angelico <rosuav@gmail.com> - 2011-05-13 00:13 +1000
              Re: checking if a list is empty Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-05-12 11:08 +1200
    Re: checking if a list is empty Chris Rebert <clp2@rebertia.com> - 2011-05-06 13:46 -0700
    Re: checking if a list is empty Chris Angelico <rosuav@gmail.com> - 2011-05-07 10:51 +1000
    Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-07 08:28 +0000
      Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-07 22:50 -0500
        Re: checking if a list is empty Ethan Furman <ethan@stoneleaf.us> - 2011-05-07 21:57 -0700
          Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-11 11:47 +0100
            Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-11 13:45 +0000
              Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-11 15:34 +0100
                Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-11 16:26 +0000
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-11 19:05 +0100
                RE: checking if a list is empty "Prasad, Ramit" <ramit.prasad@jpmchase.com> - 2011-05-11 14:44 -0400
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-11 20:26 +0100
                Learning new languages (was: checking if a list is empty) Teemu Likonen <tlikonen@iki.fi> - 2011-05-12 06:37 +0300
                Re: checking if a list is empty Chris Torek <nospam@torek.net> - 2011-05-11 19:05 +0000
                Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-11 21:42 +0000
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-12 07:23 +0100
                Re: checking if a list is empty Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-11 10:31 -0600
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-11 18:46 +0100
            Re: checking if a list is empty "D'Arcy J.M. Cain" <darcy@druid.net> - 2011-05-11 10:33 -0400
              Re: checking if a list is empty Redcat <redcat@catfolks.net> - 2011-05-11 15:31 +0000
              Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-11 18:44 +0100
              Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-11 16:24 -0500
                Re: checking if a list is empty alex23 <wuwei23@gmail.com> - 2011-05-11 20:31 -0700
                Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-11 22:53 -0500
                Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-12 06:13 +0000
                Re: checking if a list is empty "rurpy@yahoo.com" <rurpy@yahoo.com> - 2011-05-12 10:42 -0700
                Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-13 14:41 -0500
                Re: checking if a list is empty Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-13 14:21 -0600
                Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-13 19:48 -0500
                Re: checking if a list is empty Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-13 19:52 -0600
                Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-13 23:47 -0500
                Re: checking if a list is empty Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-14 00:14 -0600
                Re: checking if a list is empty Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-05-14 14:32 +1200
                Re: checking if a list is empty Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-05-14 14:26 +1200
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-12 07:13 +0100
                Re: checking if a list is empty Ben Finney <ben+python@benfinney.id.au> - 2011-05-12 16:46 +1000
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-12 08:28 +0100
                Re: checking if a list is empty Ben Finney <ben+python@benfinney.id.au> - 2011-05-12 17:37 +1000
                Re: checking if a list is empty "D'Arcy J.M. Cain" <darcy@druid.net> - 2011-05-12 01:49 -0400
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-12 07:21 +0100
                Re: checking if a list is empty Chris Angelico <rosuav@gmail.com> - 2011-05-12 22:16 +1000
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-12 13:43 +0100
                Re: checking if a list is empty Chris Angelico <rosuav@gmail.com> - 2011-05-12 23:20 +1000
                Re: checking if a list is empty Hans Georg Schaathun <hg@schaathun.net> - 2011-05-13 09:47 +0100
        Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-08 14:07 +0000
          Re: checking if a list is empty Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-05-08 18:59 +0300
          Re: checking if a list is empty Terry Reedy <tjreedy@udel.edu> - 2011-05-08 18:41 -0400
          Re: checking if a list is empty Michael Torrie <torriem@gmail.com> - 2011-05-08 21:31 -0600
          Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-08 22:33 -0500
            Re: checking if a list is empty Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-08 22:34 -0600
              Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-09 16:58 -0500
                Re: checking if a list is empty Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-09 23:34 +0000
                Re: checking if a list is empty Ben Finney <ben+python@benfinney.id.au> - 2011-05-10 09:54 +1000
                Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-09 19:10 -0500
                Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-09 19:19 -0500
            Re: checking if a list is empty James Mills <prologic@shortcircuit.net.au> - 2011-05-09 14:46 +1000
          Re: checking if a list is empty harrismh777 <harrismh777@charter.net> - 2011-05-08 22:56 -0500
          Re: checking if a list is empty Terry Reedy <tjreedy@udel.edu> - 2011-05-09 17:30 -0400
          Re: checking if a list is empty Chris Torek <nospam@torek.net> - 2011-05-12 03:49 +0000

csiph-web