PEP 276 Simple Iterator for ints (fwd)

Jeff Shannon jeff at ccvcorp.com
Wed Nov 28 18:06:30 EST 2001


David Eppstein wrote:

> In article <mailman.1006976198.7280.python-list at python.org>,
>  James_Althoff at i2.com wrote:
>
> >
> > With such an iterator one could write (with *no* syntax changes to Python):
> >
> >     for i in table.rowcount:
> >         for j in table.colcount:
> >             print table.value(i,j)
>
> I don't care for it -- is it really natural and intuitive
> that "x in y" should be equivalent to "0 <= x < y" when x and y are both
> ints?  E.g. that "3 in 5" is true but "-2 in 5" is false?  Is this a
> natural mathematical operation to include as one of the fundamental ones in
> a language?

Um, maybe I've missed something, but what does this have to do with iterators?
An iterator will never return results to a constant (thus, your "3 in 5" example
is still a syntax error).  PEP 276 does not make an integer equivalent to the
list of natural numbers ending below it;  it simply provides a way to *iterate*
over those numbers, in the context of a for-loop.  "if x in 5" would still be an
invalid construct, even after "for x in 5" became legal.  (Unless I'm *severely*
misunderstanding the intent...)

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list