More fun with PEP 276

James Althoff jamescalthoff at
Wed Dec 12 22:34:23 EST 2001

Tim Delaney wrote:
>And we come full circle ... again ...

Understandable sentiment.

But in going around the circle (again), I think there
have been some interesting discussions.  And this time
around we have working, demo implementations for two
of the suggestions, namely:

    for i in -5 < ints() < 5:


    for i in -5/span/5:

Both of the above handle all variations of open and
closed intervals with explicit operators, have
mechanisms for steps different than 1, handle both
increasing and decreasing intervals, support shortcuts
(the latter more so than the former, though), work
both inside and outside a for-loop, use an
iterator-based approach without actualizing a list
unnecessarily, do not make literal syntax for lists
any more complex, and -- in the forms listed above --
require no syntax changes and no new keywords and are
backwards compatible with existing Python.

Are they better than xrange?  At least for the case of
a decreasing, open-on-the-left, closed-on-the-right
interval with variable bounds they seem more natural
(I would claim):

    for i in xrange(a-1,b-1,-1):


    for i in a > ints() >= b:


    for i in a/span//b:


p.s. And Note that PEP 276 itself (merely) suggests
adding an iterator to class int which could exist
independently from any or none of the above.  (I know,
we've been around that circle before, too. <wink>).

Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at
or bid at

More information about the Python-list mailing list