@internal<EOL>def iterSort(iterators, cmpFn):
actual = []<EOL>_iterators = []<EOL>for i, it in enumerate(iterators):<EOL><INDENT>try:<EOL><INDENT>a = next(it)<EOL>_iterators.append((i, it))<EOL>actual.append(a)<EOL><DEDENT>except StopIteration:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>while True:<EOL><INDENT>if not _iterators:<EOL><INDENT>return<EOL><DEDENT>elif len(_iterators) == <NUM_LIT:1>:<EOL><INDENT>originIndex, it = _iterators[<NUM_LIT:0>]<EOL>yield originIndex, actual[<NUM_LIT:0>]<EOL>for item in it:<EOL><INDENT>yield originIndex, item<EOL><DEDENT>return<EOL><DEDENT>minimum = None<EOL>minimumIndex = None<EOL>secondMin = None<EOL>for i, val in enumerate(actual):<EOL><INDENT>skipSecMinCheck = False<EOL>if minimum is None:<EOL><INDENT>minimum = val<EOL>minimumIndex = i<EOL><DEDENT>elif cmpFn(val, minimum):<EOL><INDENT>secondMin = minimum<EOL>minimum = val<EOL>minimumIndex = i<EOL>skipSecMinCheck = True<EOL><DEDENT>elif not skipSecMinCheck and (<EOL>secondMin is None or cmpFn(val, secondMin)):<EOL><INDENT>secondMin = val<EOL><DEDENT><DEDENT>actualI, actualIt = _iterators[minimumIndex]<EOL>while not cmpFn(secondMin, minimum):<EOL><INDENT>yield (actualI, minimum)<EOL>try:<EOL><INDENT>minimum = next(actualIt)<EOL><DEDENT>except StopIteration:<EOL><INDENT>minimum = None<EOL>break<EOL><DEDENT><DEDENT>if minimum is None:<EOL><INDENT>del _iterators[minimumIndex]<EOL>del actual[minimumIndex]<EOL><DEDENT>else:<EOL><INDENT>actual[minimumIndex] = minimum<EOL><DEDENT><DEDENT>
Sort items from iterators(generators) by alwas selecting item
with lowest value (min first)

:return: generator of tuples (origin index, item) where origin index
    is index of iterator in "iterators" from where item commes from