def peekiter ( iterable ) : it = iter ( iterable ) one = next ( it ) def gen ( ) : """Generator that returns first and proxy other items from source""" yield one while True : yield next ( it ) return ( one , gen ( ) )
fastest way to iterate over an iterator python
Return first row and also iterable with same items as original
def peekiter(iterable):
    """Return first row and also iterable with same items as original"""
    it = iter(iterable)
    one = next(it)

    def gen():
        """Generator that returns first and proxy other items from source"""
        yield one
        while True:
            yield next(it)
    return (one, gen())