Coding style

Carl Banks pavlovevidence at gmail.com
Wed Jul 19 15:15:01 EDT 2006


Patrick Maupin wrote:
> The original post did not say "this function is iterating twice over
> the same data."  It only said that there might be a significant
> computational cost on an empty iterator, and wished that the code would
> somehow throw an exception to alert the programmer to this cost.

You're misrepresenting what I said.  Cost was merely the
best-case-scenario.  Bugs could arise if, say, the finalization
silently depends on non-empty iterable.


> But this is still not a good reason why, in the general
> case, "if len(lst)" should be preferred over "if lst".

Whatever.  The OP asked for a reason one should be preferred over the
other; this was simply one reason to use "if len(lst)>0".  Not good
enough for you?  Fine, you still have all the reasons to continue to
use "if lst" (as opposed to just bashing "if len(lst)>0") that you and
others have shared with us in this thread.

(Wait a second....)


Carl Banks




More information about the Python-list mailing list