PEP 276 Simple Iterator for ints (fwd)

James_Althoff at i2.com James_Althoff at i2.com
Wed Nov 28 14:35:45 EST 2001


*** modified resend ***

Fernando Perez wrote:
>well, while on the topic why not go for full math notation?
>for i in [0,1,..,5), (0,1,..,5], etc.
>
>That would satisfy all math options for semi-open, semi-closed
>intervals, and send every brace-matching text editor on the face of
>this planet into a fit :-)
>
>I get a feeling this PEP isn't going to get too far...

Just another reminder for those who haven't followed the entire thread (or
perhaps didn't read the PEP ;-)

... 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)

Doesn't help David Eppstein write better pseudo-code for his algorithms
class, doesn't add Haskell-like-lazy-lists-created-from-closed-intervals
functionality, doesn't generalize slicing notation for half-open
intervals, etc.   It just eliminates the need to use or think about range
and xrange in common cases like the example above.

Jim


--
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list