def pairiter(seq):
    """Returns an iterator that yields consecutive pairs from seq."""
    it = iter(seq)
    while True:
        try:
            yield [next(it), next(it)]
        except (RuntimeError, StopIteration):
            return
