[Python-ideas] Integrate some itertools into the Python syntax
Ethan Furman
ethan at stoneleaf.us
Mon Mar 28 12:29:27 EDT 2016
On 03/28/2016 09:13 AM, Chris Barker wrote:
> On Mon, Mar 28, 2016 at 7:45 AM, Franklin? Lee wrote:
>
>> I'm still very uneasy about how slicing is usually random access,
>> and doesn't change how it indexes its elements from repeated use. It
>> means that you have something very different for the same syntax.
>
> I think only slightly different :-)
> On Mon, Mar 28, 2016 at 8:04 AM, Chris Angelico wrote:
>
>> >>> range(10, 100)[25:35]
>> range(35, 45)
>>
>> It's a slice. Whether it's random access or not is pretty much
>> unrelated to slicing; you get a slice of the underlying object,
>> whatever that is. A slice of a sliceable iterator should be a sliced
>> iterator.
>
> sure -- but that works great for range, because is is an lazy evaluated
> sequence, which of course makes it iterable, but I think the trick is:
>
> arbitrary_iterable[10:20]
>
> should return an iterable that will return the 10th to the 20th item
> when iterated
Iter*ables* are easy to slice (think list, tuple, range, etc.).
Iter*ators* are the tricky ones. And yes, there is no way to slice an
iterator without changing its state.
--
~Ethan~
More information about the Python-ideas
mailing list