[Python-Dev] Allowing slicing of iterators (original) (raw)
Guido van Rossum gvanrossum at gmail.com
Mon Jan 24 16:25:27 CET 2005
- Previous message: [Python-Dev] Allowing slicing of iterators
- Next message: [Python-Dev] Allowing slicing of iterators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I just wrote a new C API function (PyItemGetItem) that supports slicing for arbitrary iterators. A patch for current CVS is at http://www.python.org/sf/1108272
For simple indices it does the iteration manually, and for extended slices it returns an itertools.islice object. As a trivial example, here's how to skip the head of a zero-numbered list: for i, item in enumerate("ABCDEF")[1:]: print i, item Is this idea a non-starter, or should I spend my holiday on Wednesday finishing it off and writing the documentation and tests for it?
Since we already have the islice iterator, what's the point? It seems to me that introducing this notation would mostly lead to confuse users, since in most other places a slice produces an independent copy of the data.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Allowing slicing of iterators
- Next message: [Python-Dev] Allowing slicing of iterators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]