f | def joinseq(*sequences): | f | def joinseq(*sequences): |
| iterators = [iter(seq) for seq in sequences] | | iterators = [iter(seq) for seq in sequences] |
| iterators_count = len(iterators) | | iterators_count = len(iterators) |
| iterator_array = [None] * iterators_count | | iterator_array = [None] * iterators_count |
n | for i, it in enumerate(iterators): | n | for i, iterator in enumerate(iterators): |
| el = next(it, None) | | element = next(iterator, None) |
| if el is not None: | | if element is not None: |
| iterator_array[i] = el | | iterator_array[i] = element |
| else: | | else: |
| iterator_array[i] = None | | iterator_array[i] = None |
| iterators_count -= 1 | | iterators_count -= 1 |
| while iterators_count > 0: | | while iterators_count > 0: |
| min_index = None | | min_index = None |
| min_value = None | | min_value = None |
n | for i, val in enumerate(iterator_array): | n | for i, el in enumerate(iterator_array): |
| if val is None: | | if el is None: |
| continue | | continue |
n | if min_value is None or val < min_value: | n | if min_value is None or el < min_value: |
| min_value = val | | min_value = el |
| min_index = i | | min_index = i |
| if min_index is not None: | | if min_index is not None: |
| yield min_value | | yield min_value |
t | el = next(iterators[min_index], None) | t | element = next(iterators[min_index], None) |
| if el is not None: | | if element is not None: |
| iterator_array[min_index] = el | | iterator_array[min_index] = element |
| else: | | else: |
| iterator_array[min_index] = None | | iterator_array[min_index] = None |
| iterators_count -= 1 | | iterators_count -= 1 |