Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!feeder.news-service.com!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'algorithms': 0.07; 'args': 0.07; 'distinction': 0.07; 'terry': 0.07; 'python': 0.07; 'commonly': 0.09; 'dict': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'am,': 0.14; 'wrote:': 0.14; 'expression).': 0.16; 'hides': 0.16; 'non-empty': 0.16; 'reedy': 0.16; 'statements.': 0.16; 'versus': 0.16; 'question.': 0.18; 'jan': 0.22; 'subject:list': 0.22; 'header:In-Reply-To:1': 0.22; 'fundamental': 0.23; 'vs.': 0.23; '(not': 0.24; 'suspect': 0.25; 'string': 0.29; 'toward': 0.29; 'list': 0.30; 'called': 0.32; 'to:addr:python-list': 0.32; '...': 0.32; 'done,': 0.33; 'test': 0.33; 'connection': 0.33; 'header:X-Complaints-To:1': 0.34; 'change': 0.34; 'returned': 0.35; 'header:User-Agent:1': 0.35; 'some': 0.37; 'useful': 0.37; 'steven': 0.38; 'but': 0.38; 'received:org': 0.38; 'set': 0.39; 'common': 0.39; 'to:addr:python.org': 0.39; 'header:Mime-Version:1': 0.39; 'empty': 0.40; 'header:Received:5': 0.40; 'results': 0.61; 'common,': 0.84; 'cupboard': 0.84; 'inductive': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: checking if a list is empty Date: Sun, 08 May 2011 18:41:20 -0400 References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: rain.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 In-Reply-To: <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> 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: 31 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1304894496 news.xs4all.nl 81476 [::ffff:82.94.164.166]:46578 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4965 On 5/8/2011 10:07 AM, Steven D'Aprano wrote: > Because the test of "is this nothing, or something?" is a common, useful > test: Because inductive algorithms commonly branch on 'input is something' (not done, change args toward 'nothing'and recurse or iterate) versus 'input is nothing (done, return base expression). > 0 (nothing) vs 1, 2, 3, ... (something) > empty list versus non-empty list > empty dict versus non-empty dict > empty set versus non-empty set > empty string versus non-empty string and non-inductive algorithms also branch on the same question. > no search results returned versus some search results returned > no network connection available versus some network connection available > no food in the cupboard versus food in the cupboard > > This is a fundamental distinction which is very useful in practice. Definitely. Python commonly hides the distinction inside of iterators called by for statememts, but StopIteration is understood as 'collection is empty'. An I suspect something vs. nothing is also the most common overt condition in if and while statements. -- Terry Jan Reedy