Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: checking if a list is empty Date: Thu, 12 May 2011 11:08:04 +1200 Lines: 23 Message-ID: <930j6nFi2lU1@mid.individual.net> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net exBjng08jR5pa1vF5jQ0AANZ4KXe3UAlge6vokDwStaao+Tnlw Cancel-Lock: sha1:siTQmx8MFJzWyv1ebPte2DyIJZg= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5175 Hans Georg Schaathun wrote: > 0 is a number as real and existent as any other, > one would think that the empty list is also as real and existent as > any other list. 0 does have some special properties, though, such as being the additive identity and not having a multiplicative inverse. Adding falseness as another special property isn't too much of a stretch and turns out to be useful. Likewise, it's useful to treat empty containers as having a similar special property, since they're often a base or terminating case in algorithms. It's especially useful in a dynamic language where any additional operations such as finding the length or comparing with zero has a run-time cost. Yes, you have to learn it, but it's a small thing to learn with a considerable payoff. -- Greg