Re: [Python-Dev] Allowing slicing of iterators

2005-01-26 Thread Nick Coghlan
Guido van Rossum wrote: Iterators are for single sequential access. It's a feature that you have to import itertools (or at least that you have to invoke its special operations) -- iterators are not sequences and shouldn't be confused with such. I agree the semantic difference between an iterable

Re: [Python-Dev] Allowing slicing of iterators

2005-01-25 Thread Guido van Rossum
[me] Since we already have the islice iterator, what's the point? [Nick] I'd like to see iterators become as easy to work with as lists are. At the moment, anything that returns an iterator forces you to use the relatively cumbersome itertools.islice mechanism, rather than Python's native

Re: [Python-Dev] Allowing slicing of iterators

2005-01-25 Thread Steven Bethard
Nick Coghlan wrote: In the example below (printing the first 3 items of a sequence), the fact that sorted() produces a new iterable list, while reversed() produces an iterator over the original list *should* be an irrelevant implementation detail from the programmer's point of view. You

Re: [Python-Dev] Allowing slicing of iterators

2005-01-25 Thread Josiah Carlson
Nick Coghlan [EMAIL PROTECTED] wrote: Guido van Rossum wrote: Since we already have the islice iterator, what's the point? I'd like to see iterators become as easy to work with as lists are. At the moment, anything that returns an iterator forces you to use the relatively cumbersome

Re: [Python-Dev] Allowing slicing of iterators

2005-01-25 Thread Steven Bethard
Raymond Hettinger [EMAIL PROTECTED] wrote: FWIW, someone (Bengt Richter perhaps) once suggested syntactic support differentiated from sequences but less awkward than a call to itertools.islice(). itertools.islice(someseq, lo, hi) would be rendered as someseq'[lo:hi]. Just to make sure I'm

Re: [Python-Dev] Allowing slicing of iterators

2005-01-25 Thread Nick Coghlan
Steven Bethard wrote: If we're really looking for a builtin, wouldn't it be better to go the route of getattr/setattr and have something like getslice that could operate on both lists and iterators? Such a builtin should probably be getitem() rather than getslice() (since getitem(iterable,

[Python-Dev] Allowing slicing of iterators

2005-01-24 Thread Nick Coghlan
I just wrote a new C API function (PyItem_GetItem) 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

Re: [Python-Dev] Allowing slicing of iterators

2005-01-24 Thread Guido van Rossum
I just wrote a new C API function (PyItem_GetItem) 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