itertools comments [Was: Re: RELEASED: Python 2.3a2]
Alex Martelli
aleax at aleax.it
Fri Feb 21 17:16:28 EST 2003
Alexander Schmolck wrote:
> Alex Martelli <aleax at aleax.it> writes:
>>
>> > I think xrange, etc. are already a convention for the closest thing
>> > Python has traditionally had to iterators. Maybe those functions
>> > should just be updated to make ordinary iterators.
>>
>> Not without breaking, e.g., xrange(23, 17923, 12)[15] -- which now
>> has a perfectly good result of 203 and would break if xrange
>> returned an iterator (or any other non-indexable object).
>
> It could always return and indexable iterator.
Yes, it's not forbidden for an iterator object to be also
indexable -- weird (but then some would say xrange objects
already ARE weird, I guess) but not forbidden. Similarly,
len(xrange(7)) would have to keep returning 7, etc.
So what would be the added value of forcing:
x = xrange(n)
assert x is iter(x)
to be true? It would only seem to break such usage as:
N_times = xrange(N)
for i in N_times:
for j in N_times:
process(i, j)
What advantage would you think breaking this usage would
confer? Or, if you agree that breaking this usage is a
DIS-advantage (albeit not a huge one), what would in your
opinion be the compensating advantages? I just cannot see
any -- but it is, of course, quite possible that I'm just
having a blind spot, so, please explain, thanks!
Alex
More information about the Python-list
mailing list