def _pair_iter(it):
 it = iter(it)
 prev = next(it)
 for el in it:
  (yield (prev, el))
  prev = el
 (yield (prev, None))

def _pair_iter ( it ) : it = iter ( it ) prev = next ( it ) for el in it : ( yield ( prev , el ) ) prev = el ( yield ( prev , None ) )
yields pairs of tokens from the given iterator such that each input token will appear as the first element in a yielded tuple .