Neil Cerutti wrote: > For use in a hand-coded parser I wrote the following simple > iterator with look-ahead.
There's a recipe for this: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/304373 Note that the recipe efficiently supports an arbitrary look-ahead, not just a single item. > I haven't thought too deeply about what peek ought to return > when the iterator is exhausted. Suggestions are respectfully > requested. In the recipe, StopIteration is still raised on a peek() operation that tries to look past the end of the iterator. STeVe -- http://mail.python.org/mailman/listinfo/python-list