PEP 276 Simple Iterator for ints (fwd)

James_Althoff at James_Althoff at
Tue Dec 11 13:42:46 EST 2001

Christopher A. Craig wrote:
>I may be wrong, there may be some class of problems where you really
>want to use a foreach style "for" loop to iterate over a set of
>integers (other than a half-open, increment by one range for sequence
>indexing), but I can't think of what that might be.

Go right back to David's example and let's suppose that instead of just
printing each integer I need to make a list of such numbers and pass them
off somewhere else.  With David's scheme you can use list comprehensions.
With the while-loop approach you have to revert to the mylist.append()
idiom.  Adding list comprehensions to Python wasn't a necessity, but some
feel that it is a nice mechanism for certain situations.  The same goes
with intervals.  Sometimes it isn't best to look at things in strict


More information about the Python-list mailing list