recognizing empty iterators

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Mon Jul 21 20:54:03 EDT 2003


> From: Bengt Richter [mailto:bokr at oz.net]
>
> If iterators had a .peek() method for 1-item lookahead, maybe 
> that would
> be easy to implement. If empty, it could raise StopIteration, 
> and otherwise
> return what next() would return, without disturbing the state 
> w.r.t. next().

So create an iterator that has a `peek` method, and wrap all iterators in that. Easy!

Tim Delaney





More information about the Python-list mailing list