[Python-ideas] Add lookahead iterator (peeker) to itertools
Masklinn
masklinn at masklinn.net
Mon Feb 25 13:02:30 CET 2013
On 2013-02-25, at 11:08 , Paul Moore wrote:
>
>>>> from lookahead import lookahead
>>>> it = lookahead(range(3))
>>>> list(it)
> <hangs>
>
> The problem is that once you wrap an iterator with lookahead() you
> can't use the underlying iterator directly any more without losing
> data, as you've consumed a value from it. So you have to use the
> wrapped version
That's a drawback to most itertools wrappers though, and one which
makes sense since Python iterators and generators are not
replayable/restartable.
More information about the Python-ideas
mailing list