PEP 276 Simple Iterator for ints (fwd)

David Eppstein eppstein at ics.uci.edu
Wed Nov 28 15:30:29 EST 2001


In article <mailman.1006976198.7280.python-list at python.org>,
 James_Althoff at i2.com wrote:

> ... Although PEP 276 has stimulated much interesting discussion about new
> syntax for specifying integer intervals, PEP 276 itself does not call for
> any such syntactic changes to Python.  It (merely) suggests adding an
> *iterator* to types.IntType (using stuff that is already fully supported in
> Python 2.1) to make more convenient the common case of using an index to
> access items in a sequence (in a for-loop) when direct access to said items
> is not practical (as in the case of a multi-dimensional table, for
> example).
> 
> 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?

If the goal is to make it easy to avoid range() in for loops, I'd prefer to 
see it done in a way that makes sense semantically and not just because 
it's a short previously-unused syntax.  Hence my continued contribution to 
the discussion of alternatives.
-- 
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