tee_lookahead

iteration_utilities.tee_lookahead(tee, i)

Inspect the i-th upcomping value from a tee() object while leaving the tee() object at its current position.

Parameters:

tee : itertools.tee()

The tee object in which to look ahead.

i : int

The index counting from the current position which should be peeked.

Returns:

peek : any type

The element at the i-th upcoming index in the tee object.

Raises:

IndexError

If the underlying iterator doesn’t have enough values.

Examples

>>> from iteration_utilities import tee_lookahead
>>> from itertools import tee
>>> t1, t2 = tee([1,2,3,4,5,6])
>>> tee_lookahead(t1, 0)
1
>>> tee_lookahead(t1, 1)
2
>>> tee_lookahead(t1, 0)
1