An iterator with look-ahead
George Sakkis
george.sakkis at gmail.com
Wed Jan 10 12:00:15 EST 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:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/304373
George
More information about the Python-list
mailing list