[Python-ideas] Integrate some itertools into the Python syntax
Chris Barker
chris.barker at noaa.gov
Mon Mar 28 12:13:22 EDT 2016
On Mon, Mar 28, 2016 at 7:45 AM, Franklin? Lee <
leewangzhong+python at gmail.com> 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 <rosuav at gmail.com> 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 -- doable, but:
for i in arbitrary_iterable[10:20]:
pass
will then have to call the underlying iterable 20 times -- if it's an
iterator that isn't a sequence, its state will have been altered.
so I'm not sure how to go about this -- but it would be nice.
Also, arbitrary_iterable[-10:]
would be essentially impossible.
-CHB
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160328/9c20cc8b/attachment.html>
More information about the Python-ideas
mailing list