def finite_alternator(length, *args):
    """Return a finite repeating alternator for args."""
    c = 0
    while args and c < length:
        for a in args:
            yield a
            c += 1
            if c >= length:
                break
Return a finite repeating alternator for args.
recipes/Python/139210_repeating_alternator/recipe-139210.py