def iter_interleave(*iterables):
    """
    A generator that interleaves the output from a one or more iterators
    until they are *all* exhausted.

    """
    iterables = map(iter, iterables)
    while iterables:
        result = []
        for it in iterables:
            try:
                result.append(it.next())
            except StopIteration:
                iterables.remove(it)
        print result
        for item in result:
            yield item

    A generator that interleaves the output from a one or more iterators
    until they are *all* exhausted.

    
recipes/Python/576665_Interleaving_file_lines_using/recipe-576665.py