Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.tornevall.net!weretis.net!feeder5.news.weretis.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.05; 'disagree': 0.07; 'does.': 0.07; 'pep': 0.07; 'python': 0.07; 'argument,': 0.09; 'frankly': 0.09; 'kelly': 0.09; 'null,': 0.09; 'operator,': 0.09; 'sake': 0.09; 'throw': 0.09; 'to:name:python list': 0.09; 'pm,': 0.11; 'wrote:': 0.14; 'concise,': 0.16; 'discourse': 0.16; 'surprising': 0.16; '\xc2\xa0if': 0.16; 'fine': 0.18; 'suggest': 0.19; 'describes': 0.19; 'language': 0.20; '(which': 0.21; 'seeing': 0.21; 'subject:list': 0.22; 'header:In- Reply-To:1': 0.22; 'mon,': 0.22; '"not': 0.23; "i'm": 0.26; 'message-id:@mail.gmail.com': 0.28; 'testing': 0.28; 'problem': 0.29; '(even': 0.29; 'bound': 0.29; 'fine.': 0.29; 'list': 0.30; 'argue': 0.31; 'clear,': 0.31; 'construct': 0.31; 'list"': 0.31; 'solved': 0.31; 'perhaps': 0.32; 'to:addr:python-list': 0.32; '...': 0.32; 'posts': 0.33; 'relatively': 0.33; 'yourself.': 0.33; 'things': 0.33; 'community': 0.33; 'skip:" 10': 0.34; 'actually': 0.34; 'suggestion': 0.35; 'put': 0.35; 'explicit': 0.35; 'stands': 0.35; 'quite': 0.36; 'doing': 0.36; 'else': 0.37; 'some': 0.37; 'should': 0.37; 'received:google.com': 0.38; 'ways': 0.38; 'no.': 0.38; 'to:addr:python.org': 0.39; 'empty': 0.40; 'would': 0.40; 'header:Received:5': 0.40; '2011': 0.62; 'perfectly': 0.65; 'received:74.125.83': 0.69; 'concerns': 0.80; 'now...': 0.84; 'something.': 0.91 MIME-Version: 1.0 In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> From: James Mills Date: Mon, 9 May 2011 14:46:45 +1000 Subject: Re: checking if a list is empty To: python list Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 52 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1304916448 news.xs4all.nl 41102 [::ffff:82.94.164.166]:47828 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4979 On Mon, May 9, 2011 at 2:34 PM, Ian Kelly wrote: > "bool(list)" describes whether the list contains something. =C2=A0"Not" > being a logical operator, it stands to reason that "not list" should > mean the same thing as "not bool(list)". =C2=A0Anything else would be > surprising and pointlessly convoluted. =C2=A0If "not list" bothers you, > then I would suggest that your problem is actually with "bool(list)". I concur! +1 >> =C2=A0 =C2=A0 =C2=A0 =C2=A0... =C2=A0should return True only if 'list' i= s bound to NULL, or if the >> name 'list' would throw a name exception... [...] >> =C2=A0 =C2=A0 =C2=A0 =C2=A0... =C2=A0and, Python should have an explicit= way of testing for an empty >> list that is clear, concise, and easy to understand even for the relativ= ely >> new Python programmer. =C2=A0This is not intended to generate counter ar= gument, >> its just my feedback on a language construct that I find to be inconsist= ent >> logically. ... Please, no pedantic discourse explaining why I'm wrong... >> just put in into a PEP and move on. =C2=A0:) > > It does. =C2=A0"if len(list) =3D=3D 0" Again +1 on the if len(list) =3D=3D 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 --=20 -- James Mills -- -- "Problems are solved by method"