beginning index for generators
Peter Otten
__peter__ at web.de
Sun Oct 17 07:39:40 EDT 2004
Andrew Dalke wrote:
> BTW, this is kinda cute with your code
>
> >>> list(irange("A", "AAAAAAAAA", "A"))
> ['A', 'AA', 'AAA', 'AAAA', 'AAAAA', 'AAAAAA', 'AAAAAAA', 'AAAAAAAA']
> >>>
This is of course completely accidental and strongly discouraged :-)
On the other hand I don't like arbitrary limitations like that of the sum()
built-in.
>>>And that's itertools.islice?
>>
>>
>> No, but it _calls_ itertool.islice() as you may have noted :-)
>> Its raison d'être is that it allows to pass the start, stop, and step
>> attributes of a slice object without looking into the special cases.
>
> Acutally I didn't notice. I was on my way out the door and didn't
> look that closely. My apologies.
De nada. It _was_ named suggestively to trigger your perception.
> Given the worry you had above about the sys.maxint limit, aren't
> you also concerned about the same limits with itertools.islice?
I'm not especially worried about these limits, I just didn't like the look
of xrange(start, sys.maxint-step+1, step) (?) as the substitute for an
open-ended sequence and decided to do it right - after all large indices
are a corner case where the 'iterate' class shines if the iterable is
"indexable", too. As to itertools.islice(), anyone who throws away, say,
the first 2**31 values of an iteration has probably other things than
Python's limitations to worry about.
Peter
More information about the Python-list
mailing list