Recap: PEP 276 Simple Iterator for ints

James_Althoff at James_Althoff at
Fri Nov 16 23:46:51 CET 2001

Marc-Andre Lemburg wrote:
>Since for-loops always use iterators there's no problem here:
>even if one of the constructs does not return an iterator
>compatible sequence, the for-loop will wrap this object using a
>generic sequence iterator.

Yes, it is understood that sequences work in for-loops.

The point is that, presumably, there are times when one would prefer not to
actualize a very large list merely to *iterate* through its values.
Perhaps I'm off on this, but it would seem that "xrange" exists because of
this.  Otherwise, why would "range" not suffice? (I know, some think it
does ;-).

It seems to me that, given the need (or desire) for both a list constructor
and an iterator, you either provide both -- and add extra
ugliness/complexity to your syntax and/or calling conventions in the
process (the "x" in "xrange", for example) -- or you provide the iterator
in convenient form and the list constructor in less convenient form (as you
propose by using the list function on the return of an iterator from a
slice on integers).  Or you don't provide the iterator at all and don't
worry about big lists.  My comment was put in to encourage folks to take
this tradeoff into account when detailing similar proposals.

Thanks for your ideas.


More information about the Python-list mailing list