I would like an enumerate-like functional on iterators which yields the pair (previous_element, current_element). That is, given that iter>
enumerate
(previous_element, current_element)
iter>
What about the simple (obvious) solution?
def offset(iterable): prev = None for elem in iterable: yield prev, elem prev = elem