checking if a list is empty

Ethan Furman ethan at stoneleaf.us
Wed May 11 11:53:24 EDT 2011


Hans Georg Schaathun wrote:
> On 11 May 2011 13:36:02 GMT, Steven D'Aprano
>   <steve+comp.lang.python at pearwood.info> wrote:
> : > In this case, the interpretation of an arbitrary object as a boolean is
> : > peculiar for python.  
> : 
> :  Incorrect. It is widespread among many languages. Programmers have been 
> :  writing conditional tests using arbitrary values since 1958 when Lisp 
> :  introduced the concept.
> 
> 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.


Like so many other things Python got right, I think it got this right as 
well.  "something" vs "nothing" is simple, useful, and easy to remember.


> By now we have gotten past that old-fashioned idea that 0
> is not a number.  Computer scientists even tend to count 0 as a
> natural number.  When 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.

Python is not concerned with whether it exists -- that's a name binding; 
  Python is concerned with whether anything is there.  0 apples is 
nothing and a an empty list is nothing as well.

~Ethan~



More information about the Python-list mailing list