[Python-ideas] Add lookahead iterator (peeker) to itertools
Serhiy Storchaka
storchaka at gmail.com
Mon Feb 25 21:21:03 CET 2013
On 25.02.13 20:53, Antoine Pitrou wrote:
>>> def test_lookahead():
>>> it = iter('abc')
>>> while True:
>>> it, peeking = itertools.tee(it)
>>
>> This should be outside a loop.
>
> Only if you restrict yourself to access peeking each time you access it.
> (which, I suppose, is not the general use case for the lookahead
> proposal)
Only if your do not want to consume O(N) memory and spend O(N**2) time.
More information about the Python-ideas
mailing list