def roundrobin(*iterables):
    """roundrobin('ABC', 'D', 'EF') --> A D E B F C"""
pending = len(iterables)
nexts = cycle(iter(it).__next__ for it in iterables)
while pending:
    pass
Alternating between iterators in Python