Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'wed,': 0.04; '+0100,': 0.07; 'something,': 0.07; 'false,': 0.09; 'length.': 0.09; 'pm,': 0.11; '>>>': 0.12; 'wrote:': 0.14; 'modelled.': 0.16; 'non-empty': 0.16; 'programming': 0.20; 'subject:list': 0.22; 'header:In-Reply- To:1': 0.22; 'values': 0.23; 'oriented': 0.23; 'objects': 0.24; 'object': 0.27; 'lists': 0.28; 'looks': 0.28; 'message- id:@gmail.com': 0.30; 'list': 0.30; 'do.': 0.31; 'determine': 0.31; 'to:addr:python-list': 0.32; '...': 0.32; 'test': 0.33; 'print': 0.35; 'header:User-Agent:1': 0.35; 'usually': 0.36; 'properties': 0.36; 'steven': 0.38; 'received:google.com': 0.38; 'to:addr:python.org': 0.39; 'empty': 0.40; "it's": 0.40; 'header:Received:5': 0.40; 'domain': 0.40; '2011': 0.62; 'truth': 0.65; 'received:74.125.83': 0.69; 'received:home': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=2c3+lFaRV/k1ClG87NMLmK96AP5KNfSKAtJ0TJ2Ct/0=; b=TYPt1LdQEGJycQOjltLE2chdZn9SmwG68Zg+gVnFVc5SkS7Qr0e38Hzh7qU33rMZrA TsVkYHC3WfV/RdHBalcJNhX5qU1gq14yCcnRc+1NUul+IzG1fdMDRWhaIR03W0Gw+VKD 8E5ALEtMFe5BhF+Kq/y/zFlmeXvIpR/y27jHE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=QMyeYNsi3rd0txLBuGkHnipJdfLk+zlfUEYQTEeJwnkSKX5a5oklMzknKchLj2Iltx uEwwqMU1oaKpOe+O26iqS1tihW0U6tq/0BIRjJi3C3t5DbxHjxXCFM640i2Z/jjhZsfX nbkn5M7hqdLoFu9HtMOBgRZ78Ozn/P4BquVl4= Date: Wed, 11 May 2011 15:09:51 -0700 From: Steven Howe User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Thunderbird/3.1.10 MIME-Version: 1.0 To: python-list@python.org Subject: Re: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 25 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305151798 news.xs4all.nl 81481 [::ffff:82.94.164.166]:40512 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5167 On 05/11/2011 02:47 PM, Steven D'Aprano wrote: > On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote: > >> One principle of object oriented programming is to bestow the objects >> with properties reflecting known properties from the domain being >> modelled. Lists do not have truth values in the application domain > Yes they do. Empty lists are nothing, ergo false, and non-empty lists are > something, ergo true. > > > >>> a=[] > >>> if a: > ... print 'Yes' > ... > >>> a=[1] > >>> if a: > ... print 'Yes' > ... > Yes Cool; I'd never of thought to try that method to determine if a list was empty. I usually test it's length. This looks faster.