[Python-ideas] Add lookahead iterator (peeker) to itertools
Antoine Pitrou
solipsis at pitrou.net
Mon Feb 25 11:07:17 CET 2013
Le Sun, 24 Feb 2013 22:41:48 -0500,
Terry Reedy <tjreedy at udel.edu> a écrit :
>
> def test_lookahead():
> it = lookahead('abc')
> while it:
> a = it.peek
> b = next(it)
> print('next:', b, '; is peek:', a is b )
def test_lookahead():
it = iter('abc')
while True:
it, peeking = itertools.tee(it)
try:
a = next(peeking)
except StopIteration:
break
b = next(it)
print('next:', b, '; is peek:', a is b )
Regards
Antoine.
More information about the Python-ideas
mailing list