import itertools


def round_robin (* iterables):
    """Yield elements from `iterables` in round-robin sequence.

    Recipe credited to George Sakkis by Python documentation for itertools.

    >>> print (", ".join (str (x) for x in round_robin ([1, 2, 3], "AB", "uvwxyz")))
    1, A, u, 2, B, v, 3, w, x, y, z

    """
    def advancer (it) :
        ### Python 2.x uses `it.next`
        ### Python 3.x uses `it.__next__`
        ### but `next (it)` is supported by 2.7 and 3.x
        return lambda : next (it)
    pending = len (iterables)
    nexts   = itertools.cycle (advancer (iter (it)) for it in iterables)
    while pending:
        try:
            for nxt in nexts:
                yield nxt ()
        except StopIteration:
            pending -= 1
            nexts    = itertools.cycle (itertools.islice (nexts, pending))