PEP 276 Simple Iterator for ints (fwd)
David Eppstein
eppstein at ics.uci.edu
Wed Dec 5 22:21:43 EST 2001
In article <mailman.1007602329.14054.python-list at python.org>,
"Delaney, Timothy" <tdelaney at avaya.com> wrote:
> > I meant translating
> >
> > for 0 <= i < 10:
> > print i
> >
> > into
> >
> > i = 0
> > while i < 10:
> > print i
> > i += 1
> >
> > There is no iterator here.
>
> This would not work with either the old or the new semantics of for loops.
> It would mean that you would have for loops which in this one particular
> case behaved differently to all other cases. That would classify as a severe
> wart.
I agree: if "for x in list" doesn't change subsequent iterations if you
rebind x or list within the loop body, neither should "for x <= i < y"
or whatever similar syntax one uses. So that means, it should construct an
iterator and then act as if it were called by "for i in iterator" (I
hesitate to write an explicit formula for the iterator because of
difficulty getting it right when x or y may be non-integer).
--
David Eppstein UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list
mailing list