def merge(*iterators):
    """Merges a collection of iterators, returning a single iterator that yields
    the elements of the original iterators in non-decreasing order.  Each of
    the original iterators is assumed to yield its elements in non-decreasing
    order."""
done = object()
n = [next(it, done) for it in iterators]
while any(v is not done for v in n):
    v, i = min((v, i) for i, v in enumerate(n) if v is not done)
yield v
n[i] = next(iterators[i], done)
how to use python iterators elegently