[Python-ideas] Add lookahead iterator (peeker) to itertools

Masklinn masklinn at masklinn.net
Mon Feb 25 13:56:12 CET 2013


On 2013-02-25, at 13:37 , Joao S. O. Bueno wrote:

> Hi all!
> 
> What is the problem with iterttols.tee even?
> It is almots the samething - although much more flexible, than what is
> proposed on this thread.
> 
> 
>>>> from itertools import tee
>>>> my_iter, peek = tee(iter(range(3)), 2)
>>>> next(peek)
> 0
>>>> next(my_iter)
> 0
>>>> 

Verbose way to do the same thing: you have to tee() + next() once per
"peek()". And splitting to subroutines means these subroutines will have
to return an iterator alongside any potential value as they'll have to
tee() themselves.



More information about the Python-ideas mailing list