[Python-iterators] While we're at it...

Michael Hudson mwh at python.net
Sat Jun 30 07:37:51 EDT 2001


"Eduard Hiti" <eduard.hiti at t-online.de> writes:

> |
> | Anything else come to mind?  The core language coverage is pretty broad
> | already, so lots of stuff in the .py libraries should "just work by magic"
> | with any iterable argument.  OTOH, we all have blind spots, and, e.g., I
> | never would have thought of the "right-hand side of a multiple-target
> | assignment stmt" context on my own.
> |
> 
> Could iterators be made slicable?
> 
> Then a 'fib()[3:6]' would give you the third to fifth fibonacci numbers.

I'm not sure that's a good idea, but I would like to see an
"iterators" module that provided various common iterator
manipulations, so you could have eg:

def slice(it, lo, hi):
    for i in range(lo):
        it.next()
    for i in range(hi - lo):
        yield it.next()

Cheers,
M.

-- 
 Very clever implementation techniques are required to implement this
 insanity correctly and usefully, not to mention that code written
 with this feature used and abused east and west is exceptionally
 exciting to debug.       -- Erik Naggum on Algol-style "call-by-name"



More information about the Python-list mailing list