An iterator with look-ahead

George Sakkis george.sakkis at
Wed Jan 10 18:00:15 CET 2007

Neil Cerutti wrote:

> For use in a hand-coded parser I wrote the following simple
> iterator with look-ahead. I haven't thought too deeply about what
> peek ought to return when the iterator is exhausted. Suggestions
> are respectfully requested. As it is, you can't be sure what a
> peek() => None signifies until the next iteration unless you
> don't expect None in your sequence.

There is a different implementation in the Cookbook already:


More information about the Python-list mailing list