[Python-ideas] Variations on a loop
Georg Brandl
g.brandl at gmx.net
Sat Aug 30 15:11:00 CEST 2008
Bruce Leban schrieb:
>
> On Fri, Aug 29, 2008 at 1:47 PM, David Blaschke
> <dwblas at gmail.com
> <mailto:dwblas at gmail.com>> wrote:
>
> This idea
> elif x == funky_empty:
> result = 'no data'
>
> Can be accomplished with
> if not len(items):
> result = 'no data'
> which means that part of the proposal can be scratched IMHO.
>
>
> Not quite: len(items) requires iterating across the entire list which
> may not be necessary or desirable. Plus you may need an intermediate
> variable to store it. I think that's inferior.
This is moot anyway: in general, iterators have no __len__().
Georg
--
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.
More information about the Python-ideas
mailing list