[BangPypers] Truth Tests (bool)

Senthil Kumaran senthil at uthcode.com
Wed Jan 11 14:04:18 CET 2012

On Wed, Jan 11, 2012 at 09:49:58AM +0530, Noufal Ibrahim wrote:

> > It is not clear what you want from your description.  To check if a
> > list is empty, see if len( list ) is zero.
> You don't want to do that. Your "list" might be a generator (unless you
> check for type which is a bad idea anyway) and "len"ing that will
> consume it which might be a potentially expensive operation. 

While the explaination on __nonzero__ is useful out of this context,
how can list be a generator? I am assuming that none are confusing the

In practical cases for testing boolean in lists, just use the list as
the test. Empty list is false.


More information about the BangPypers mailing list