Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'context': 0.04; 'python.': 0.05; 'instance,': 0.05; 'operator': 0.05; 'c++,': 0.07; 'python': 0.07; 'eof': 0.09; 'c++': 0.12; 'am,': 0.14; 'wrote:': 0.14; 'bitwise': 0.16; 'boolean': 0.16; 'expression,': 0.16; 'handy': 0.16; 'statements;': 0.16; 'language': 0.20; 'not.': 0.22; 'subject:list': 0.22; 'header:In-Reply-To:1': 0.22; 'thu,': 0.22; '(and': 0.22; 'extensively': 0.23; 'state:': 0.23; 'objects': 0.24; "what's": 0.24; 'java': 0.24; 'equivalent': 0.26; "i'm": 0.26; 'chris': 0.27; 'object': 0.27; 'message-id:@mail.gmail.com': 0.28; 'error': 0.29; 'list': 0.30; 'i/o': 0.31; 'syntax,': 0.31; 'fact': 0.31; 'language.': 0.31; 'all,': 0.31; 'to:addr:python- list': 0.32; 'bit': 0.33; 'array': 0.33; 'test': 0.33; 'actually': 0.34; 'implies': 0.35; 'else': 0.37; 'some': 0.37; 'table': 0.37; 'received:209.85': 0.37; 'be,': 0.38; 'convenient': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'code:': 0.38; 'languages': 0.38; 'them,': 0.38; 'help': 0.39; 'php': 0.39; 'to:addr:python.org': 0.39; 'where': 0.39; 'received:209': 0.39; 'whatever': 0.39; 'similar': 0.40; "it's": 0.40; 'header:Received:5': 0.40; 'combined': 0.60; '2011': 0.62; 'legal': 0.64; 'plus': 0.65; 'truth': 0.65; 'learnt': 0.68; 'evaluate': 0.72; 'learned': 0.73; 'stream': 0.73; 'with,': 0.73; 'exploited': 0.84; 'received:209.85.210.174': 0.84; 'received :mail-iy0-f174.google.com': 0.84; 'further,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=qPPxUrrxRSvXhTZcbJHUzd++Tu4iRWqiZ0DY68vV8MQ=; b=TOEAfe0/Yct33T8o6Naj/sLZNPEOJ2Y3mvufECedd0RiGttwppzru9wpzIN/X53Iy4 z94bxSaeEmpj9TP8V/elZp0Swzju9GCa0HDEPq6KEbVATVO1U1wLPmhPpN9HdYr4KTk6 mr0bsyVHDlIibKVcMFewSug33Yp0CoCjeFNuc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=OH8o2+iXSBjLZ8yaQykagmbkEHJYcInxF4WV9AHLPMR1xP3xaQh9taOcSFeN2UcFHu fiowEOvXgVKxBmsif+VbrPmUe2EnQ5qh8E4+cIwKp4+ecNHj6MMkFdP+qrq0SzaqPd3x WsyqXcX4jJNOJ0xbgt8r5SnZMpq5GilA1Afck= MIME-Version: 1.0 In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Date: Thu, 12 May 2011 00:46:47 +1000 Subject: Re: checking if a list is empty From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 45 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305125212 news.xs4all.nl 41114 [::ffff:82.94.164.166]:45344 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5122 On Thu, May 12, 2011 at 12:00 AM, Hans Georg Schaathun wrote: > The fact that you need to list language by language which objects > evaluate as false or equivalent to false illustrates that this has > to be learnt language by language. Allowing arbitrary objects is > one thing, the particular interpretation is peculiar. Languages have to be learned language by language. Yes, you want to be similar to others if you can (and in 'most every language where it's legal syntax, "1+2" will mean "3"), but whenever I'm working in a language with which I'm not _really_ fluent, I like to keep an operator table handy (precedence, plus oddments like what the exponentiation operator is, or whether & is bitwise or boolean). They do differ, and if I'm writing in PHP or Python or Pike or C++ or Java or whatever else it be, I have to use the operators the way the interpreter/compiler will understand them, not in some other way that I "deem better". > Mentioning C, with no Boolean type at all, in this context is a bit > absurd. Understanding boolean evaluation in C is very little help > when you want to understand it in python. Actually, it's not. # Python code: if x: statements /* C code: */ if (x) { statements; } What's the difference? Both of them let you test the truth of some arbitrary object or expression, and neither of those statements implies a Boolean type. In C++, this is exploited extensively with, for instance, the stream I/O objects evaluating as false when in an error or EOF state: while (infile) infile >> *ptr++; // Compact and convenient way to read into an array Actually that one can be combined down even further, but for clarity I leave it like that. Chris Angelico