What way is the best to check an empty list?

Carl Banks pavlovevidence at gmail.com
Wed Mar 25 19:34:32 EDT 2009


On Mar 25, 8:27 am, Andre Engels <andreeng... at gmail.com> wrote:
> On Wed, Mar 25, 2009 at 4:21 PM, andrew cooke <and... at acooke.org> wrote:
>
> > but i may be wrong - are there any containers (apart from pathological
> > hand-crafted examples) that would not define __len__()?
>
> When writing my answer, I thought of generators, but I now find that
> those will have boolean value 'true' whether or not they have
> something to generate, so they will go wrong under either method.

Yes, but notice that one of them goes wrong by raising an exception,
whereas the other goes wrong by failing silently.


Carl Banks



More information about the Python-list mailing list